mudlet/src/XMLimport.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

2157 lines
90 KiB
C++
Raw Permalink Normal View History

2009-02-06 03:39:14 +01:00
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016-2023 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2016-2017 by Ian Adkins - ieadkins@gmail.com *
* *
2009-02-06 03:39:14 +01:00
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "XMLimport.h"
2021-04-02 19:10:16 +01:00
#include "dlgMapper.h"
#include "LuaInterface.h"
Improve: Secure credential management with system keychain integration and legacy migration (#7956) #### Brief overview of PR changes/additions This pull request implements secure credential management for Mudlet with system keychain integration and encrypted fallback storage: **Core Components:** - **CredentialManager**: High-level API for secure credential storage with QtKeychain integration - **SecureStringUtils**: Qt-based cryptographic utilities for encrypted file storage - **Legacy Migration**: Automatic detection and migration of existing plaintext passwords **Key Features:** - **System Keychain Integration**: Primary storage in macOS Keychain, Windows Credential Store, and Linux Secret Service via QtKeychain - **Encrypted File Fallback**: Qt crypto-based AES encryption for portable mode and keychain unavailability - **Seamless Migration**: Automatic detection and upgrade of legacy password storage formats - **Profile Isolation**: Per-profile encryption keys prevent cross-profile credential access - **Portable Mode Support**: Automatic detection and secure file-based storage for portable installations #### Motivation for adding to Mudlet **Security Enhancement:** - Eliminates plaintext password storage in profile XML files - Provides industry-standard system keychain integration for credential security - Implements authenticated encryption for fallback scenarios **User Experience:** - Zero configuration required - works automatically across all platforms - Seamless migration from existing plaintext passwords to secure storage - Native system integration provides familiar credential management experience **Future-Proofing:** - Extensible architecture supports additional credential types (API keys, tokens, etc.) - Robust fallback ensures functionality in all deployment scenarios - Prepares foundation for OAuth and external service integrations #### Other info (issues closed, discussion etc) **Security Architecture:** - **Keychain-First Strategy**: Prefers system keychain with automatic encrypted file fallback - **Legacy Format Detection**: Automatically migrates passwords from development branch keychain format - **Memory Security**: Secure string clearing and controlled credential lifecycle management - **Input Validation**: Path traversal protection and service name sanitization **Implementation Highlights:** - **Async Operations**: Non-blocking keychain operations with timeout protection - **Thread Safety**: Event-driven architecture prevents UI blocking and race conditions - **Comprehensive Testing**: Full test coverage for encryption, migration, and fallback scenarios - **Cross-Platform**: Unified API across Windows, macOS, and Linux with platform-specific optimizations **Version Compatibility & Migration:** - **Mudlet 4.19.x Compatibility**: Preserves existing plaintext password storage to ensure compatibility when switching between 4.19.x stable and development builds - **Mudlet 4.20.x Migration**: Post-4.20.0 release, automatic migration begins converting plaintext passwords to secure storage - **Bidirectional Safety**: Users can safely run both 4.19.x and development versions without losing access to their passwords during the transition period - **Legacy Format Support**: Automatically detects and migrates passwords from the original development branch keychain format (`service="Mudlet profile"`) to the new secure format # Credential Management Workflows ## 1. Credential Storage Strategy ```mermaid flowchart TD A[Store Password Request] --> B{Portable Mode?} B -->|Yes| C[Encrypt & Store in Profile File] B -->|No| D[Store in System Keychain] D --> E{Keychain Success?} E -->|Yes| F[Remove Encrypted Fallback File] E -->|No| G[Fallback to Encrypted File] F --> H[Success] G --> I{Encryption Success?} I -->|Yes| H I -->|No| J[Failure] C --> I classDef primary fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef decision fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef result fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class D,F primary class C,G fallback class B,E,I decision class H,J result ``` ## 2. Legacy Migration Workflow ```mermaid flowchart TD A[Retrieve Password Request] --> B[Try New Keychain Format] B --> C{Password Found?} C -->|Yes| D[Return Password] C -->|No| E[Check Legacy Keychain Format] E --> F{Legacy Found?} F -->|Yes| G[Migrate to New Format] G --> H[Store in New Format] H --> I[Remove Legacy Entry] I --> J[Return Migrated Password] F -->|No| K[Try Encrypted File] K --> L{File Found?} L -->|Yes| M[Decrypt & Return] L -->|No| N[Return Empty - No Password Stored] classDef newformat fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef legacy fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef migration fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff classDef fallback fill:#607D8B,stroke:#263238,stroke-width:2px,color:#fff classDef result fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff class B,H newformat class E,I legacy class G migration class K fallback class D,J,M,N result ``` ## 3. Cross-Platform Keychain Integration ```mermaid flowchart TD A[QtKeychain Request] --> B{Platform Detection} B -->|macOS| C[Access Keychain Services] B -->|Windows| D[Access Credential Store] B -->|Linux| E[Access Secret Service] C --> F[Store/Retrieve Credential] D --> F E --> F F --> G{Operation Success?} G -->|Yes| H[Return Result] G -->|No| I[Log Error & Fallback] I --> J[Use Encrypted File Storage] J --> K[AES Encryption with Profile Key] K --> L[Store in Profile Directory] classDef platform fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef keychain fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef crypto fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class C,D,E platform class F,H keychain class I,J fallback class K,L crypto ``` This implementation provides a comprehensive, secure, and user-friendly credential management system that seamlessly upgrades existing Mudlet installations while providing robust security for future credential storage needs. --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-17 06:44:38 -04:00
#include "CredentialManager.h"
#include "SecureStringUtils.h"
Enhance: add per profile dictionary capability (#2358) This is a squash and merge PR and the following is an edited summary of the individual commit messages that were combined into it: It is saved at the end of a session and the affix file ('profile.aff') is maintained to allow for the Hunspell suggestion capability to operate. The word-list ('profile.dic') file is checked at session start to accommodate manual editing (adding/removing words) between sessions. When a word typed on the command line is not found in the main (system provided on non-Windows OSes) instead of the red (now wavy on Unix, dotted on macOS) underline a cyan dashed underline is used to show that the word was found in the profile's own dictionary. Words can also be added and removed. Also found out why the wavy / dashed underline was not showing in previous/ initial attempt. Some lua commands are also added: * addWordToDictionary((string) word) returns true if the word was added (and was not already in the dictionary) * removeWordFromDictionary((string) word) returns true if the word was present and removed from the dictionary. * getDictionaryWordList()` returns a (sorted into system locale case insensitive order) list of ALL words in the profile dictionary. * `getDictionaryWordList((string) word [,(bool)useProfileDictionary])` do a check in the specified system dictionary (default) or if a second argument is supplied and is `true` use the per profile one. Returns `true` if the word is found present in the dictionary, and false if not. * spellCheckWord((string) word) [,(bool)useUserDictionary]) returns true if the word is in the dictionary - uses the main language dictionary as set in the profile preferences unless a second, optional boolean true argument is provided then it will use the user's stored word list - either the per profile or the shared across profiles as set in the profile preferences. * spellSuggestWord((string) word [,(bool)useUserDictionary]) does the same sort of suggestions search as is done on the console command line and returns a list of suggestions from the specified system dictionary (default) or if a second argument is supplied and is `true` then it will use the user's stored word list - either the per profile or the shared across profiles as set in the profile preferences. Also: * Arrange to not list supplemental medical dictionaries. * Improve system dictionary selection by added text for all the dictionaries I can identify in my Linux system distribution. * Reordered some items in the mudlet constructor initialisation list to match their placement in the header file - it was helpful to do this as I found I needed to add an initialiser for a pointer and wanted to put it in the right place. * Revise: add more Hunspell dictionary details found on FreeBSD Also switch to consider the `.aff` files in case there are additional or supplemental `.dic` files. Some dictionaries were also found which used a '-' as a separator, particularly where the language code had a third element. Officially the language codes should have a lower case first part (language), an upper case second part (country or large scale classification) and if there is a third part it should be in "Title" case. To enable quick look-up the QMap is populated with all lowercase keys and with all '-' converted to '_'. Fix things so that the selected dictionary is in view when the preferences dialogue is created. Do not bother to check the return values from Hunspell_add and Hunspell_remove - they do not seem to be useful. Improve the dictionary location code to work for using bundled dictionaries when building in a shadow directory. (I found this whilst building in my slightly non-standard Windows build environment). Refactor: * mudlet::prepareProfileDictionary(...) * mudlet::prepareSharedDictionary() * mudlet::saveDictionary(...) so that they use a number of common subroutines. Change the lua getDictionaryWordList so that its output is sorted in a case-insensitive manner instead of a case-sensitive manner. Also handle the case should a main dictionary not be found. Revise: after peer review disable the option to NOT use a user dictionary As there is some careful coding in the existing code to prevent unnecessary loading and unloading of the per profile and shared user dictionaries it is easier to just prevent the option to disable both of them from being chosen - at least whilst evaluating things - this will maintain the presence of the "mEnableUserDictionary = 'yes'" option in new profile saves. Revise: recheck word after dict. options changes & clear marks when off As requested during peer review - this in fact improves upon situation before the start of adding user dictionaries. Revise: recheck word after adding/removing it from user's dictionary It is better now at changing the indication between unknown and in the user's dictionary for a word that is not in the main one - but it is not perfect, especially if there are additional punctuation marks abutting the word concerned. Also added indication of which of the per profile or the shared user dictionaries is providing the user dictionary suggestions. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-03-08 09:28:55 +01:00
#include "TConsole.h"
#include "TMap.h"
#include "TRoomDB.h"
#include "TRoom.h"
#include "VarUnit.h"
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
#include "mudlet.h"
#include <QBuffer>
infrastructure: decouple the mapper engine from UI dialogs (#9513) #### Brief overview of PR changes/additions - Removes all raw Qt Widgets usage from the map engine: `TMap.{h,cpp}` no longer owns a `QProgressDialog` (and drops a dead `QFileDialog` include), and `XMLimport.{h,cpp}` no longer pulls in `QApplication` (the clipboard read now uses `QGuiApplication::clipboard()`, which lives in Qt Gui). - The standalone map-progress dialog (shown when the mapper is not visible, for map download / XML import and JSON export/import) is now driven by Qt signals carrying pre-translated payloads; the frontend (`TMainConsole`) owns the actual `QProgressDialog`, and a user cancel returns to the engine through `TMap::slot_mapProgressDialogCancelled()`. - Adds `MapProgressDialogSeamTest` covering the transfer-progress state machine, a JSON export/import round trip driving the new signals, a mid-import cancel delivered through the seam (the highest-risk change, since the JSON reader used to poll `QProgressDialog::wasCanceled()` synchronously), and an XML map import re-entered from inside a running JSON operation. #### Motivation for adding to Mudlet Second concrete step of the re-scoped libmudlet plan (a Qt-Widgets-free `mudlet_core` for headless use, testability and WASM). It copies the seam template established in #9507: core emits a pre-translated payload -> frontend owns the widget -> a callback slot returns the answer. The Qt Widgets dependency audit (`cmake/audit-core-widgets.sh`) drops from **151 to 147** offending files; `TMap.cpp`, `TMap.h`, `XMLimport.cpp` and `XMLimport.h` are all now clean. The mapper-owned inline progress path (`dlgMapper`/`T2DMap`, Mudlet's own widgets) is deliberately untouched here - those move wholesale in the later target-split phase. #### Other info (issues closed, discussion etc) Part of #8681 / #9011. Existing translations are unaffected: every progress string keeps its `TMap` `tr()` context, so current translations carry straight over. Two new strings do arrive, both with `//:` translator comments - the warnings shown when a map download or an XML map import is refused because a JSON import/export is already running. The JSON dialog stays non-modal and the download/import dialog keeps its modeless styling, each applied by the frontend. The engine keeps its own `mMapProgressStandalone` / `mMapProgressCancelRequested` / `mMapProgressStandaloneMaximum` state to replace the widget read-backs it used to do (`!= nullptr`, `wasCanceled()`, `maximum()`). If a map operation ever reaches the engine before a console is wired (checked via `isSignalConnected`), `TMap::warnIfMapProgressUnwired()` logs a loud `qWarning` rather than silently running with no progress UI. It also closes a latent null-dereference that exists on `development` today. With the mapper visible a map download takes the inline-progress path, leaving `mpProgressDialog` null - so a JSON export started meanwhile sails past the `if (mpProgressDialog)` "already in progress" check and creates a dialog of its own. When the download then finishes inside the `processEvents()` pump the export is running, `clearTransferProgress()` deletes and nulls *that* dialog, and the export's next `incrementJsonProgressDialog()` dereferences null. The engine now records whose dialog is up (`mMapProgressIsTransfer`) so a transfer only ever closes its own, and `importMap()` refuses to start while a JSON operation holds the progress - the mirror of the guard `downloadMap()` has. Two review-driven details worth flagging: the frontend only wires the dialog's cancel to the engine when the operation is actually cancelable, so a non-cancelable local XML import no longer turns a window-close into a spurious "Map download was canceled" message; and the standalone download/import dialog is now parented to the console (like the JSON one always was, and like #9507's package-download dialog), so it centres on and dies with the profile window. The three `#include <QApplication>` additions to `Host.cpp` / `dlgTriggerEditor.cpp` / `dlgConnectionProfiles.cpp` replace the transitive include they used to get from `XMLimport.h`; all three are already Qt Widgets consumers, so the audit count is unaffected. Assisted-by: Claude:claude-opus-4-8 Assisted-by: Claude:claude-opus-5 **Test case:** With a mapper window open, use a game that supports map download (or call `downloadMap()`) and confirm the progress dialog shows, updates, and its Abort cancels the download. Then with the mapper window closed, run `exportJsonMap()` and `importJsonMap()` on a large map and confirm the non-modal JSON progress dialog appears, updates its Areas/Rooms/Labels counts, and that clicking Abort during an import stops it with an "aborted by user" result. Load a local XML map (Settings -> Map -> load) and confirm closing its progress window does not print a "Map download was canceled" line. Everything should behave exactly as on `development`. #### Demo (before & after) https://github.com/user-attachments/assets/f1c62580-2d03-4e5b-a6ee-f6e2b78d113d
2026-08-02 15:33:07 +02:00
#include <QClipboard>
#include <QGuiApplication>
#include <QtMath>
Improve: Secure credential management with system keychain integration and legacy migration (#7956) #### Brief overview of PR changes/additions This pull request implements secure credential management for Mudlet with system keychain integration and encrypted fallback storage: **Core Components:** - **CredentialManager**: High-level API for secure credential storage with QtKeychain integration - **SecureStringUtils**: Qt-based cryptographic utilities for encrypted file storage - **Legacy Migration**: Automatic detection and migration of existing plaintext passwords **Key Features:** - **System Keychain Integration**: Primary storage in macOS Keychain, Windows Credential Store, and Linux Secret Service via QtKeychain - **Encrypted File Fallback**: Qt crypto-based AES encryption for portable mode and keychain unavailability - **Seamless Migration**: Automatic detection and upgrade of legacy password storage formats - **Profile Isolation**: Per-profile encryption keys prevent cross-profile credential access - **Portable Mode Support**: Automatic detection and secure file-based storage for portable installations #### Motivation for adding to Mudlet **Security Enhancement:** - Eliminates plaintext password storage in profile XML files - Provides industry-standard system keychain integration for credential security - Implements authenticated encryption for fallback scenarios **User Experience:** - Zero configuration required - works automatically across all platforms - Seamless migration from existing plaintext passwords to secure storage - Native system integration provides familiar credential management experience **Future-Proofing:** - Extensible architecture supports additional credential types (API keys, tokens, etc.) - Robust fallback ensures functionality in all deployment scenarios - Prepares foundation for OAuth and external service integrations #### Other info (issues closed, discussion etc) **Security Architecture:** - **Keychain-First Strategy**: Prefers system keychain with automatic encrypted file fallback - **Legacy Format Detection**: Automatically migrates passwords from development branch keychain format - **Memory Security**: Secure string clearing and controlled credential lifecycle management - **Input Validation**: Path traversal protection and service name sanitization **Implementation Highlights:** - **Async Operations**: Non-blocking keychain operations with timeout protection - **Thread Safety**: Event-driven architecture prevents UI blocking and race conditions - **Comprehensive Testing**: Full test coverage for encryption, migration, and fallback scenarios - **Cross-Platform**: Unified API across Windows, macOS, and Linux with platform-specific optimizations **Version Compatibility & Migration:** - **Mudlet 4.19.x Compatibility**: Preserves existing plaintext password storage to ensure compatibility when switching between 4.19.x stable and development builds - **Mudlet 4.20.x Migration**: Post-4.20.0 release, automatic migration begins converting plaintext passwords to secure storage - **Bidirectional Safety**: Users can safely run both 4.19.x and development versions without losing access to their passwords during the transition period - **Legacy Format Support**: Automatically detects and migrates passwords from the original development branch keychain format (`service="Mudlet profile"`) to the new secure format # Credential Management Workflows ## 1. Credential Storage Strategy ```mermaid flowchart TD A[Store Password Request] --> B{Portable Mode?} B -->|Yes| C[Encrypt & Store in Profile File] B -->|No| D[Store in System Keychain] D --> E{Keychain Success?} E -->|Yes| F[Remove Encrypted Fallback File] E -->|No| G[Fallback to Encrypted File] F --> H[Success] G --> I{Encryption Success?} I -->|Yes| H I -->|No| J[Failure] C --> I classDef primary fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef decision fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef result fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class D,F primary class C,G fallback class B,E,I decision class H,J result ``` ## 2. Legacy Migration Workflow ```mermaid flowchart TD A[Retrieve Password Request] --> B[Try New Keychain Format] B --> C{Password Found?} C -->|Yes| D[Return Password] C -->|No| E[Check Legacy Keychain Format] E --> F{Legacy Found?} F -->|Yes| G[Migrate to New Format] G --> H[Store in New Format] H --> I[Remove Legacy Entry] I --> J[Return Migrated Password] F -->|No| K[Try Encrypted File] K --> L{File Found?} L -->|Yes| M[Decrypt & Return] L -->|No| N[Return Empty - No Password Stored] classDef newformat fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef legacy fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef migration fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff classDef fallback fill:#607D8B,stroke:#263238,stroke-width:2px,color:#fff classDef result fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff class B,H newformat class E,I legacy class G migration class K fallback class D,J,M,N result ``` ## 3. Cross-Platform Keychain Integration ```mermaid flowchart TD A[QtKeychain Request] --> B{Platform Detection} B -->|macOS| C[Access Keychain Services] B -->|Windows| D[Access Credential Store] B -->|Linux| E[Access Secret Service] C --> F[Store/Retrieve Credential] D --> F E --> F F --> G{Operation Success?} G -->|Yes| H[Return Result] G -->|No| I[Log Error & Fallback] I --> J[Use Encrypted File Storage] J --> K[AES Encryption with Profile Key] K --> L[Store in Profile Directory] classDef platform fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef keychain fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef crypto fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class C,D,E platform class F,H keychain class I,J fallback class K,L crypto ``` This implementation provides a comprehensive, secure, and user-friendly credential management system that seamlessly upgrades existing Mudlet installations while providing robust security for future credential storage needs. --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-17 06:44:38 -04:00
#include <QVersionNumber>
improve: improve memory safety by using smart pointers (#9239) ### Refactor: replace raw pointer ownership with smart pointers across core subsystems #### Brief overview of PR changes/additions Replaces raw pointer ownership patterns with `std::unique_ptr` and `std::map` across several core subsystems: - **Host**: `mStopWatchMap` (`QMap<int, stopWatch*>` → `std::map<int, unique_ptr<stopWatch>>`), `profileShortcuts` (`QMap<QString, QKeySequence*>` → `std::map<QString, unique_ptr<QKeySequence>>`). Removes `qDeleteAll` in destructor and `delete mMMCPServer`. - **TMap**: `mpRoomDB` raw pointer → `unique_ptr` - **VarUnit**: `base` raw pointer → `unique_ptr` - **TTrigger**: condition map storage converted to `unique_ptr`, destructor simplified - **discord**: handler and presence maps converted from raw pointer `QMap` to `unique_ptr` + `std::map` - **Updater**: `mFeed` and `mUpdateDialog` converted to `unique_ptr` #### Motivation for adding to Mudlet These patterns were identified as sources of memory leaks and potential use-after-free bugs. Using smart pointers makes ownership explicit, eliminates manual cleanup code, and ensures correct destruction even on early-exit paths. #### Other info (issues closed, discussion etc) sorry this one is still pretty big, but most of the changes are the same for each thing so reviewing them together probably makes sense. sadly there isn't much to see here other than no slow uptick of heap size :-[ Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:42:09 +12:00
#include <memory>
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
XMLimport::XMLimport(Host* pH)
2017-04-19 15:27:12 -07:00
: mpHost(pH)
2009-02-06 03:39:14 +01:00
{
}
std::pair<bool, QString> XMLimport::importPackage(QFile* pfile, QString packName, int moduleFlag, QString* pVersionString)
2009-02-06 03:39:14 +01:00
{
2011-05-28 02:13:53 +02:00
mPackageName = packName;
setDevice(pfile);
module = moduleFlag;
2011-05-28 02:13:53 +02:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (!packName.isEmpty()) {
mpKey = new TKey(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpKey->mModuleMasterFolder = true;
mpKey->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpKey->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpKey->setIsActive(true);
mpKey->setName(mPackageName);
mpKey->setIsFolder(true);
mpTrigger = new TTrigger(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpTrigger->mModuleMasterFolder = true;
mpTrigger->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpTrigger->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpTrigger->setIsActive(true);
mpTrigger->setName(mPackageName);
mpTrigger->setIsFolder(true);
mpTimer = new TTimer(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpTimer->mModuleMasterFolder = true;
mpTimer->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpTimer->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpTimer->setIsActive(true);
mpTimer->setName(mPackageName);
mpTimer->setIsFolder(true);
mpAlias = new TAlias(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpAlias->mModuleMasterFolder = true;
mpAlias->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpAlias->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpAlias->setIsActive(true);
mpAlias->setName(mPackageName);
mpAlias->setScript(QString());
mpAlias->setRegexCode(QString());
mpAlias->setIsFolder(true);
mpAction = new TAction(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpAction->mModuleMasterFolder = true;
mpAction->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpAction->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpAction->setIsActive(true);
mpAction->setName(mPackageName);
mpAction->setIsFolder(true);
mpScript = new TScript(nullptr, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
mpScript->mModuleMasterFolder = true;
mpScript->mModuleMember = true;
}
Improve: add ancestors functions (#6726) #### Brief overview of PR changes/additions and motivation for adding Provides two Lua functions: * `isAncestorsActive(itemID, "type")` - returns a boolean which is `true` if all (if any) of the parents of the given item are set as active and `false` if any are not. It makes use of an internal template function that already exists but makes it available to the Lua sub-system. If the item does not have any ancestors this function will return `true`. * `ancestors(itemID, "type")` - returns a table containing a sub-table for each successively distance ancestor (if any) of the given item; within each sub-table are details of the ancestor, specifically: * its ID as a number * its name as a string * whether it is active as a boolean * its "node" (type), one of "item", "group" (folder) or "package" (module) ***ALSO: adds a third, optional, boolean argument to `isActive(...)` which if provided and `true` will only includes items in the count whose parents are all enabled/active - if omitted it will be treated as if it is `false` so that it behaves as the current version. Script-writers should check for the presence of one of the other two functions to determine if this third argument is handled.*** #### Other info (issues closed, discussion etc) The first function will be enough to close #6724, specifically when it is combined with `isActive(...)` as follows, it will enable a script to determine whether an item (in this example a trigger with an ID number stored as `myTriggerID`) will operate or not: ```lua if isAncestorsActive(myTriggerID, "trigger") and isActive(myTriggerID, "trigger") > 0 then -- Okay the aforesaid trigger will run! end ``` Note that these two new functions ONLY work with the ID number of an item - this is because a unique identifier is required and Mudlet allows for duplicate names so that cannot be used to reliably identify an item. It had now been made a bit easier to determine the ID number of an existing item the `findItems("name", "type")` function that has also been implemented as#6742. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-17 03:54:36 +00:00
mpScript->mPackageName = mPackageName;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpScript->setIsActive(true);
mpScript->setName(mPackageName);
mpScript->setIsFolder(true);
mpHost->getTriggerUnit()->registerTrigger(mpTrigger);
mpHost->getTimerUnit()->registerTimer(mpTimer);
mpHost->getAliasUnit()->registerAlias(mpAlias);
mpHost->getActionUnit()->registerAction(mpAction);
mpHost->getKeyUnit()->registerKey(mpKey);
mpHost->getScriptUnit()->registerScript(mpScript);
}
while (!atEnd()) {
2009-02-06 03:39:14 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("MudletPackage")) {
QString versionString;
if (attributes().hasAttribute(qsl("version"))) {
versionString = attributes().value(qsl("version")).toString();
if (!versionString.isEmpty()) {
bool isOk = false;
const float versionNumber = versionString.toFloat(&isOk);
if (isOk) {
mVersionMajor = qFloor(versionNumber);
mVersionMinor = qRound(1000.0 * versionNumber) - (1000 * mVersionMajor);
}
if (pVersionString) {
*pVersionString = versionString;
}
}
}
if (mVersionMajor > 1
/*||(mVersionMajor==1&&mVersionMinor)*/) {
// Minor check is not currently relevant, just abort on 2.000f or more
const QString moanMsg = tr("[ ALERT ] - Sorry, the file being read:\n"
"\"%1\"\n"
"reports it has a version (%2) it must have come from a later Mudlet version,\n"
"and this one cannot read it, you need a newer Mudlet!")
.arg(pfile->fileName(), versionString);
mpHost->postMessage(moanMsg);
return {false, moanMsg};
}
2009-02-06 03:39:14 +01:00
readPackage();
} else if (name() == qsl("map")) {
if (!packName.isEmpty()) {
qWarning() << "XMLimport::importPackage(...) WARNING: ignoring unexpected <map> element"
" - map data should not be present in package XML files";
} else {
readMap();
mpHost->mpMap->audit();
if (mpHost->mpMap->mpMapper) {
mpHost->mpMap->mpMapper->mp2dMap->init();
mpHost->mpMap->mpMapper->updateAreaComboBox();
mpHost->mpMap->mpMapper->resetAreaComboBoxToPlayerRoomArea();
mpHost->mpMap->mpMapper->show();
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
qDebug().nospace() << "XMLimport::importPackage(...) ERROR: "
"unrecognised element with name: "
<< name().toString() << " and content: " << text().toString();
2009-02-06 03:39:14 +01:00
}
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (!packName.isEmpty()) {
if (!gotTrigger) {
mpHost->getTriggerUnit()->unregisterTrigger(mpTrigger);
2014-09-27 02:36:11 -07:00
delete mpTrigger;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
if (gotTimer) { // packName is NOT empty for modules...!
mpTimer->setIsActive(true);
mpTimer->enableTimer(mpTimer->getID());
} else {
mpHost->getTimerUnit()->unregisterTimer(mpTimer);
2014-09-27 02:36:11 -07:00
delete mpTimer;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
if (gotAlias) {
mpAlias->setIsActive(true);
} else {
mpHost->getAliasUnit()->unregisterAlias(mpAlias);
2014-09-27 02:36:11 -07:00
delete mpAlias;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
if (gotAction) {
mpHost->getActionUnit()->updateAllToolbars();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
mpHost->getActionUnit()->unregisterAction(mpAction);
2014-09-27 02:36:11 -07:00
delete mpAction;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
if (!gotKey) {
mpHost->getKeyUnit()->unregisterKey(mpKey);
2014-09-27 02:36:11 -07:00
delete mpKey;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
if (!gotScript) {
mpHost->getScriptUnit()->unregisterScript(mpScript);
2014-09-27 02:36:11 -07:00
delete mpScript;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
return {!hasError(), errorString()};
2009-02-06 03:39:14 +01:00
}
// returns the type of item and ID of the first (root) element
std::pair<EditorViewType, int> XMLimport::importFromClipboard()
{
QString xml;
infrastructure: decouple the mapper engine from UI dialogs (#9513) #### Brief overview of PR changes/additions - Removes all raw Qt Widgets usage from the map engine: `TMap.{h,cpp}` no longer owns a `QProgressDialog` (and drops a dead `QFileDialog` include), and `XMLimport.{h,cpp}` no longer pulls in `QApplication` (the clipboard read now uses `QGuiApplication::clipboard()`, which lives in Qt Gui). - The standalone map-progress dialog (shown when the mapper is not visible, for map download / XML import and JSON export/import) is now driven by Qt signals carrying pre-translated payloads; the frontend (`TMainConsole`) owns the actual `QProgressDialog`, and a user cancel returns to the engine through `TMap::slot_mapProgressDialogCancelled()`. - Adds `MapProgressDialogSeamTest` covering the transfer-progress state machine, a JSON export/import round trip driving the new signals, a mid-import cancel delivered through the seam (the highest-risk change, since the JSON reader used to poll `QProgressDialog::wasCanceled()` synchronously), and an XML map import re-entered from inside a running JSON operation. #### Motivation for adding to Mudlet Second concrete step of the re-scoped libmudlet plan (a Qt-Widgets-free `mudlet_core` for headless use, testability and WASM). It copies the seam template established in #9507: core emits a pre-translated payload -> frontend owns the widget -> a callback slot returns the answer. The Qt Widgets dependency audit (`cmake/audit-core-widgets.sh`) drops from **151 to 147** offending files; `TMap.cpp`, `TMap.h`, `XMLimport.cpp` and `XMLimport.h` are all now clean. The mapper-owned inline progress path (`dlgMapper`/`T2DMap`, Mudlet's own widgets) is deliberately untouched here - those move wholesale in the later target-split phase. #### Other info (issues closed, discussion etc) Part of #8681 / #9011. Existing translations are unaffected: every progress string keeps its `TMap` `tr()` context, so current translations carry straight over. Two new strings do arrive, both with `//:` translator comments - the warnings shown when a map download or an XML map import is refused because a JSON import/export is already running. The JSON dialog stays non-modal and the download/import dialog keeps its modeless styling, each applied by the frontend. The engine keeps its own `mMapProgressStandalone` / `mMapProgressCancelRequested` / `mMapProgressStandaloneMaximum` state to replace the widget read-backs it used to do (`!= nullptr`, `wasCanceled()`, `maximum()`). If a map operation ever reaches the engine before a console is wired (checked via `isSignalConnected`), `TMap::warnIfMapProgressUnwired()` logs a loud `qWarning` rather than silently running with no progress UI. It also closes a latent null-dereference that exists on `development` today. With the mapper visible a map download takes the inline-progress path, leaving `mpProgressDialog` null - so a JSON export started meanwhile sails past the `if (mpProgressDialog)` "already in progress" check and creates a dialog of its own. When the download then finishes inside the `processEvents()` pump the export is running, `clearTransferProgress()` deletes and nulls *that* dialog, and the export's next `incrementJsonProgressDialog()` dereferences null. The engine now records whose dialog is up (`mMapProgressIsTransfer`) so a transfer only ever closes its own, and `importMap()` refuses to start while a JSON operation holds the progress - the mirror of the guard `downloadMap()` has. Two review-driven details worth flagging: the frontend only wires the dialog's cancel to the engine when the operation is actually cancelable, so a non-cancelable local XML import no longer turns a window-close into a spurious "Map download was canceled" message; and the standalone download/import dialog is now parented to the console (like the JSON one always was, and like #9507's package-download dialog), so it centres on and dies with the profile window. The three `#include <QApplication>` additions to `Host.cpp` / `dlgTriggerEditor.cpp` / `dlgConnectionProfiles.cpp` replace the transitive include they used to get from `XMLimport.h`; all three are already Qt Widgets consumers, so the audit count is unaffected. Assisted-by: Claude:claude-opus-4-8 Assisted-by: Claude:claude-opus-5 **Test case:** With a mapper window open, use a game that supports map download (or call `downloadMap()`) and confirm the progress dialog shows, updates, and its Abort cancels the download. Then with the mapper window closed, run `exportJsonMap()` and `importJsonMap()` on a large map and confirm the non-modal JSON progress dialog appears, updates its Areas/Rooms/Labels counts, and that clicking Abort during an import stops it with an "aborted by user" result. Load a local XML map (Settings -> Map -> load) and confirm closing its progress window does not print a "Map download was canceled" line. Everything should behave exactly as on `development`. #### Demo (before & after) https://github.com/user-attachments/assets/f1c62580-2d03-4e5b-a6ee-f6e2b78d113d
2026-08-02 15:33:07 +02:00
QClipboard* clipboard = QGuiApplication::clipboard();
std::pair<EditorViewType, int> result;
xml = clipboard->text(QClipboard::Clipboard);
QByteArray ba = xml.toUtf8();
QBuffer xmlBuffer(&ba);
setDevice(&xmlBuffer);
if (!xmlBuffer.open(QIODevice::ReadOnly)) {
qWarning() << "XMLimport::importFromClipboard() ERROR: failed to open XML buffer for reading";
return {EditorViewType::cmUnknownView, 0};
}
while (!atEnd()) {
readNext();
if (isStartElement()) {
if (name() == qsl("MudletPackage")) {
result = readPackage();
} else {
qDebug() << "ERROR:name=" << name().toString() << "text:" << text().toString();
}
}
}
return result;
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
void XMLimport::readVariable(TVar* pParent)
2013-06-09 12:25:52 -04:00
{
auto var = new TVar(pParent);
2013-06-09 12:25:52 -04:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
LuaInterface* lI = mpHost->getLuaInterface();
VarUnit* vu = lI->getVarUnit();
2013-06-09 12:25:52 -04:00
QString keyName, value;
2013-08-19 12:25:26 +02:00
int keyType = 0;
int valueType;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
const QString what = name().toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2013-06-09 12:25:52 -04:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
2013-06-09 12:25:52 -04:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("name")) {
2013-06-09 12:25:52 -04:00
keyName = readElementText();
continue;
} else if (name() == qsl("value")) { // NOLINT(readability-else-after-return)
2013-06-09 12:25:52 -04:00
value = readElementText();
continue;
} else if (name() == qsl("keyType")) { // NOLINT(readability-else-after-return)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
keyType = readElementText().toInt();
2013-06-09 12:25:52 -04:00
continue;
} else if (name() == qsl("valueType")) { // NOLINT(readability-else-after-return)
2013-06-09 12:25:52 -04:00
valueType = readElementText().toInt();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
var->setName(keyName, keyType);
var->setValue(value, valueType);
vu->addSavedVar(var);
lI->setValue(var);
2013-06-09 12:25:52 -04:00
continue;
} else if (name() == qsl("VariableGroup") || name() == qsl("Variable")) { // NOLINT(readability-else-after-return)
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readVariable(var);
} else {
readUnknownElement(what);
2013-06-09 12:25:52 -04:00
}
}
}
delete var;
2013-06-09 12:25:52 -04:00
}
void XMLimport::readHiddenVariables()
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
LuaInterface* lI = mpHost->getLuaInterface();
VarUnit* vu = lI->getVarUnit();
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("name")) {
const QString var = readElementText();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
vu->addHidden(var);
continue;
}
}
}
}
2013-06-09 12:25:52 -04:00
void XMLimport::readVariablePackage()
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
LuaInterface* lI = mpHost->getLuaInterface();
VarUnit* vu = lI->getVarUnit();
2013-06-09 12:25:52 -04:00
mpVar = vu->getBase();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2013-06-09 12:25:52 -04:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("VariableGroup") || name() == qsl("Variable")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readVariable(mpVar);
} else if (name() == qsl("HiddenVariables")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
readHiddenVariables();
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
} else {
readUnknownElement(qsl("VariablePackage"));
}
2013-06-09 12:25:52 -04:00
}
}
}
2010-01-22 01:45:34 +01:00
void XMLimport::readMap()
{
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
QMultiHash<int, int> tempAreaRoomsHash; // Keys: area id, Values: a room id in that area
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-08-25 00:41:43 +02:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("areas")) {
2013-03-22 12:47:58 +01:00
mpHost->mpMap->mpRoomDB->clearMapDB();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportStringToProgressDialog(tr("Parsing area data..."));
mpHost->mpMap->reportProgressToProgressDialog(0, 3);
2010-08-25 00:41:43 +02:00
readAreas();
} else if (name() == qsl("rooms")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportStringToProgressDialog(tr("Parsing room data..."));
mpHost->mpMap->reportProgressToProgressDialog(1, 3);
readRooms(tempAreaRoomsHash);
} else if (name() == qsl("environments")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportStringToProgressDialog(tr("Parsing environment data..."));
mpHost->mpMap->reportProgressToProgressDialog(2, 3);
2010-08-25 00:41:43 +02:00
readEnvColors();
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportProgressToProgressDialog(3, 3);
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportStringToProgressDialog(tr("Assigning rooms to their areas..."));
const int roomTotal = tempAreaRoomsHash.count();
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
int currentRoomCount = 0;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
QListIterator<int> itAreaWithRooms(tempAreaRoomsHash.uniqueKeys());
while (itAreaWithRooms.hasNext()) {
const int areaId = itAreaWithRooms.next();
2020-06-13 19:30:08 +02:00
auto values = tempAreaRoomsHash.values(areaId);
QSet<int> const areaRoomsSet{values.begin(), values.end()};
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (!mpHost->mpMap->mpRoomDB->areas.contains(areaId)) {
// It is known for map files to have rooms with area Ids that are
// not in the listed areas - this cures that:
mpHost->mpMap->mpRoomDB->addArea(areaId);
Enhance: fix map downloading code, add manual XML map importing (#329) A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) a count of 100's of rooms processed. This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. However errors for the XML map file importing process as initiated from the Lua command are generally returned to that command rather than plastered onto the main profile console. Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 08:03:42 +01:00
}
Merge branch release_30 into development_merge_30 This is The Merge to merge what is essentially a fork in release_30 back into development branch. As both branches have diverged and been actively worked on, neither is automatically right in a merge conflict - use git blame and commit timestamps, plus some reasoning as to which change is better, to figure out which conflict needs to be resolved and how. It says the origin is SlySven/release_30 - just happened to pick one of the many remotes I had, SlySven/release_30 is the latest 3.0 release. Strategy: * create a development_merge_30 branch based on development * force-merge release_30 to development_merge_30 and push with conflicts still included * send in PRs to development_merge_30 to resolve merge conflicts as we get through them * once all conflicts are gone, merge development_merge_30 into development # Conflicts: # .travis.yml # CI/travis.linux.before_install.sh # CI/travis.linux.install.sh # CMakeLists.txt # src/ActionUnit.h # src/CMakeLists.txt # src/EAction.h # src/Host.cpp # src/Host.h # src/T2DMap.cpp # src/T2DMap.h # src/TAlias.cpp # src/TAlias.h # src/TAstar.h # src/TBuffer.cpp # src/TBuffer.h # src/TConsole.cpp # src/TConsole.h # src/TEasyButtonBar.cpp # src/TEvent.h # src/TFlipButton.h # src/TLuaInterpreter.cpp # src/TLuaInterpreter.h # src/TMap.cpp # src/TMap.h # src/TRoom.cpp # src/TRoom.h # src/TRoomDB.cpp # src/TTextEdit.cpp # src/TTextEdit.h # src/TTimer.cpp # src/TTimer.h # src/TTrigger.cpp # src/Tree.h # src/XMLexport.cpp # src/XMLimport.cpp # src/XMLimport.h # src/ctelnet.cpp # src/ctelnet.h # src/dlgConnectionProfiles.cpp # src/dlgMapper.h # src/dlgProfilePreferences.cpp # src/dlgTriggerEditor.cpp # src/dlgTriggerEditor.h # src/glwidget.h # src/mudlet-lua/genDoc.sh # src/mudlet-lua/lua/GUIUtils.lua # src/mudlet-lua/tests/GUIUtils.lua # src/mudlet.cpp # src/mudlet.h # src/src.pro # src/ui/main_window.ui # src/ui/profile_preferences.ui
2017-03-27 08:06:47 +02:00
mpHost->mpMap->mpRoomDB->setAreaRooms(areaId, areaRoomsSet);
currentRoomCount += areaRoomsSet.count();
mpHost->mpMap->reportProgressToProgressDialog(currentRoomCount, roomTotal);
Enhance: fix map downloading code, add manual XML map importing (#329) A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) a count of 100's of rooms processed. This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. However errors for the XML map file importing process as initiated from the Lua command are generally returned to that command rather than plastered onto the main profile console. Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 08:03:42 +01:00
}
2010-08-25 00:41:43 +02:00
}
void XMLimport::readEnvColors()
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-08-25 00:41:43 +02:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (name() == qsl("environment")) {
2010-08-25 00:41:43 +02:00
readEnvColor();
}
}
}
void XMLimport::readEnvColor()
{
const int id = attributes().value(qsl("id")).toString().toInt();
const int color = attributes().value(qsl("color")).toString().toInt();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
Enhance: import/export map as JSON (#4546) This is so that a crowd sourced map might be edited in a collaborative manner. The first stage is to make sufficient of the entire map details be exported/imported in a modular (by area) fashion. Include Lua functions `exportJsonMap(pathFileName)` and `importJsonMap(pathFileName)` to perform the whole map export and import functions. Also, rename `(QMultiMap<int, QPair<int, int>>) TArea::exits` to: `TArea::mAreaExits` because the old name was such a common word in our source code it was hard to find the uses of this member. This format has been constructed so as to not mention the most common, or default values for some items - so as to minimise details that have to be included on the basis they can be assumed when reconstructing them on the other end. On the other hand the whole file is compressible so for storage (but not for diff/git work) archiving / compressing the file is recommended! For instance a binary map file I have is 18.6MB which produced a 25.8MB JSON file which I was able to compress down to 2.9MB - obviously this is *very* content dependent, so other's Miles-May-Vary... As the export process is not that fast include a progress dialogue that shows how many areas, map labels and rooms have been processed into the JSON format. For a 20K room map with 40 odd areas and around 800 map labels (which are awkward to convert to a text-like form) this can take 30 seconds on my 1.8GHz 4 Core PC! CodeFactor had a recommendation about a constant that I was using to set the dimension of a `char[]` (array) - it felt a compile time `constexpr` was a better thing to use. Revised to make Cancel button work in big areas: Although the existing code would abort at the end of an area, for some humongous maps with a few very large areas it is also a good idea to check for the cancel button being pressed each time the progress bar is updated. Renamed `(QMap<int, int>) TMap::envColors` to `TMap::mEnvColors` and `(QMap<int, QColor>) Tmap::customEnvColors` to `TMap::mCustomEnvColors` so that it is clearer that they are members of the `TMap` class. Add alpha component to end of list of (now four) 0 to 255 integer values returned by `getCustomEnvColorTable()` - as the corresponding setter does allow one to be provided. Move initialisers for TMap, TRoomDB, TRoom and TArea to header file where possible. As per Issue #4578. Move the default and unnamed area names from TRoomDB to TMap - as it made setting them up easier (though one of them does need to be initialised before the normal TRoomDB instance associated with the TMap is itself initialised. This meant putting these private members near the top of the header file even though we normally put private ones down the bottom. Refactor: move JSON colour writing/reading code from TArea/TRoom to TMap The code is common to all three classes so can be shared. At the same time make it explicit in the key as to whether there is an alpha component so the colour is a 24Bit opaque one or a 32Bit one with transparency. Revise: peer-review items and other tweaks Note that this revises the format version to be 1.000 (ready for release) so, although the format has not changed, any recent files produced during evaluation will need to be hand edited to change the line: "formatVersion": 0.003, to: "formatVersion": 1.000, in order to read them now. Switch to "range based" for-loops for some of the JSON additions. Fixup: ensure partially built new TRoomDB is destroyed if reading aborted Not doing this would cause a resource leak if the abort button was clicked during importation of a Json map file. Revise: disable writing out Room highlighting details It has been pointed out that the binary map format does not save the room highlighting details either - so replicate that behaviour for the moment. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
2021-02-14 23:44:55 +00:00
mpHost->mpMap->mEnvColors[id] = color;
2010-08-25 00:41:43 +02:00
}
void XMLimport::readAreas()
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-08-25 00:41:43 +02:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (name() == qsl("areas")) {
2010-08-25 00:41:43 +02:00
break;
}
if (name() == qsl("area")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
readArea();
2010-08-25 00:41:43 +02:00
}
}
}
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
void XMLimport::readArea()
2010-08-25 00:41:43 +02:00
{
if (attributes().hasAttribute(qsl("id"))) {
const int id = attributes().value(qsl("id")).toString().toInt();
const QString name = attributes().value(qsl("name")).toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->mpRoomDB->addArea(id, name);
}
2010-08-25 00:41:43 +02:00
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
void XMLimport::readRooms(QMultiHash<int, int>& areaRoomsHash)
2010-08-25 00:41:43 +02:00
{
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
unsigned int roomCount = 0;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-01-22 01:45:34 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (Q_LIKELY(isStartElement())) {
if (Q_LIKELY(name() == qsl("room"))) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
readRoom(areaRoomsHash, &roomCount);
} else {
2010-08-25 00:41:43 +02:00
readUnknownMapElement();
2010-03-15 09:37:16 +01:00
}
} else if (isEndElement() && name() == qsl("rooms")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
break;
}
2010-08-25 00:41:43 +02:00
}
2010-01-22 01:45:34 +01:00
}
void XMLimport::readRoomFeatures(TRoom* pR)
{
while (!atEnd()) {
readNext();
if (Q_LIKELY(isStartElement())) {
if (name() == qsl("features")) {
continue;
}
if (Q_LIKELY(name() == qsl("feature"))) {
readRoomFeature(pR);
}
} else if (isEndElement() && name() == qsl("features")) {
break;
}
}
}
void XMLimport::readRoomFeature(TRoom* pR)
{
if (Q_LIKELY(attributes().hasAttribute(qsl("type")))) {
pR->userData.insert(qsl("feature-%1").arg(attributes().value(qsl("type"))), qsl("true"));
}
}
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
// This is a CPU/Time hog without the non-default (true) third argument to
// TRoomDB::addRoom(...)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
void XMLimport::readRoom(QMultiHash<int, int>& areamRoomMultiHash, unsigned int* roomCount)
2010-01-22 01:45:34 +01:00
{
improve: improve memory safety by using smart pointers (#9239) ### Refactor: replace raw pointer ownership with smart pointers across core subsystems #### Brief overview of PR changes/additions Replaces raw pointer ownership patterns with `std::unique_ptr` and `std::map` across several core subsystems: - **Host**: `mStopWatchMap` (`QMap<int, stopWatch*>` → `std::map<int, unique_ptr<stopWatch>>`), `profileShortcuts` (`QMap<QString, QKeySequence*>` → `std::map<QString, unique_ptr<QKeySequence>>`). Removes `qDeleteAll` in destructor and `delete mMMCPServer`. - **TMap**: `mpRoomDB` raw pointer → `unique_ptr` - **VarUnit**: `base` raw pointer → `unique_ptr` - **TTrigger**: condition map storage converted to `unique_ptr`, destructor simplified - **discord**: handler and presence maps converted from raw pointer `QMap` to `unique_ptr` + `std::map` - **Updater**: `mFeed` and `mUpdateDialog` converted to `unique_ptr` #### Motivation for adding to Mudlet These patterns were identified as sources of memory leaks and potential use-after-free bugs. Using smart pointers makes ownership explicit, eliminates manual cleanup code, and ensures correct destruction even on early-exit paths. #### Other info (issues closed, discussion etc) sorry this one is still pretty big, but most of the changes are the same for each thing so reviewing them together probably makes sense. sadly there isn't much to see here other than no slow uptick of heap size :-[ Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:42:09 +12:00
auto pT = new TRoom(mpHost->mpMap->mpRoomDB.get());
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->id = attributes().value(qsl("id")).toString().toInt();
pT->area = attributes().value(qsl("area")).toString().toInt();
pT->name = attributes().value(qsl("title")).toString();
pT->environment = attributes().value(qsl("environment")).toString().toInt();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-01-22 01:45:34 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (Q_UNLIKELY(pT->id < 1)) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
continue; // Skip further tests on exits as we'd have to throw away
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
// this invalid room and it would mess up the
// entranceMultiHash
}
if (Q_LIKELY(name() == qsl("exit"))) {
QString dir = attributes().value(qsl("direction")).toString();
const int e = attributes().value(qsl("target")).toString().toInt();
// If there is a "hidden" exit mark it as a locked door, otherwise
// if there is a "door" mark it as an open/closed/locked door
// depending on the value (I.R.E. MUD maps always uses "1" for "door"
// and/or "hidden" - though the latter does not always appear with
// former):
const int door = (attributes().hasAttribute(qsl("hidden")) && attributes().value(qsl("hidden")).toString().toInt() == 1) ? 3
: (attributes().hasAttribute(qsl("door")) && attributes().value(qsl("door")).toString().toInt() >= 0 && attributes().value(qsl("door")).toString().toInt() <= 3)
? attributes().value(qsl("door")).toString().toInt()
: 0;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (dir.isEmpty()) {
if (attributes().value(qsl("special")).toString().toInt() == 1 && !attributes().value(qsl("command")).toString().isEmpty()) {
// This is how IRE XML maps mark special exits, rather than
// by just using a different string for the direction!
dir = attributes().value(qsl("command")).toString();
pT->setSpecialExit(e, dir);
pT->setDoor(dir, door);
} else {
continue;
}
} else if (dir == qsl("north")) {
2010-08-25 00:41:43 +02:00
pT->north = e;
pT->setDoor(qsl("n"), door);
} else if (dir == qsl("east")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->east = e;
pT->setDoor(qsl("e"), door);
} else if (dir == qsl("south")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->south = e;
pT->setDoor(qsl("s"), door);
} else if (dir == qsl("west")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->west = e;
pT->setDoor(qsl("w"), door);
} else if (dir == qsl("up")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->up = e;
pT->setDoor(qsl("up"), door);
} else if (dir == qsl("down")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->down = e;
pT->setDoor(qsl("down"), door);
} else if (dir == qsl("northeast")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->northeast = e;
pT->setDoor(qsl("ne"), door);
} else if (dir == qsl("southwest")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->southwest = e;
pT->setDoor(qsl("sw"), door);
} else if (dir == qsl("southeast")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->southeast = e;
pT->setDoor(qsl("se"), door);
} else if (dir == qsl("northwest")) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
pT->northwest = e;
pT->setDoor(qsl("nw"), door);
} else if (dir == qsl("in")) {
2010-08-25 00:41:43 +02:00
pT->in = e;
pT->setDoor(qsl("in"), door);
} else if (dir == qsl("out")) {
2010-08-25 00:41:43 +02:00
pT->out = e;
pT->setDoor(qsl("out"), door);
Merge branch release_30 into development_merge_30 This is The Merge to merge what is essentially a fork in release_30 back into development branch. As both branches have diverged and been actively worked on, neither is automatically right in a merge conflict - use git blame and commit timestamps, plus some reasoning as to which change is better, to figure out which conflict needs to be resolved and how. It says the origin is SlySven/release_30 - just happened to pick one of the many remotes I had, SlySven/release_30 is the latest 3.0 release. Strategy: * create a development_merge_30 branch based on development * force-merge release_30 to development_merge_30 and push with conflicts still included * send in PRs to development_merge_30 to resolve merge conflicts as we get through them * once all conflicts are gone, merge development_merge_30 into development # Conflicts: # .travis.yml # CI/travis.linux.before_install.sh # CI/travis.linux.install.sh # CMakeLists.txt # src/ActionUnit.h # src/CMakeLists.txt # src/EAction.h # src/Host.cpp # src/Host.h # src/T2DMap.cpp # src/T2DMap.h # src/TAlias.cpp # src/TAlias.h # src/TAstar.h # src/TBuffer.cpp # src/TBuffer.h # src/TConsole.cpp # src/TConsole.h # src/TEasyButtonBar.cpp # src/TEvent.h # src/TFlipButton.h # src/TLuaInterpreter.cpp # src/TLuaInterpreter.h # src/TMap.cpp # src/TMap.h # src/TRoom.cpp # src/TRoom.h # src/TRoomDB.cpp # src/TTextEdit.cpp # src/TTextEdit.h # src/TTimer.cpp # src/TTimer.h # src/TTrigger.cpp # src/Tree.h # src/XMLexport.cpp # src/XMLimport.cpp # src/XMLimport.h # src/ctelnet.cpp # src/ctelnet.h # src/dlgConnectionProfiles.cpp # src/dlgMapper.h # src/dlgProfilePreferences.cpp # src/dlgTriggerEditor.cpp # src/dlgTriggerEditor.h # src/glwidget.h # src/mudlet-lua/genDoc.sh # src/mudlet-lua/lua/GUIUtils.lua # src/mudlet-lua/tests/GUIUtils.lua # src/mudlet.cpp # src/mudlet.h # src/src.pro # src/ui/main_window.ui # src/ui/profile_preferences.ui
2017-03-27 08:06:47 +02:00
}
} else if (name() == qsl("coord")) {
if (attributes().value(qsl("x")).toString().isEmpty()) {
Merge branch release_30 into development_merge_30 This is The Merge to merge what is essentially a fork in release_30 back into development branch. As both branches have diverged and been actively worked on, neither is automatically right in a merge conflict - use git blame and commit timestamps, plus some reasoning as to which change is better, to figure out which conflict needs to be resolved and how. It says the origin is SlySven/release_30 - just happened to pick one of the many remotes I had, SlySven/release_30 is the latest 3.0 release. Strategy: * create a development_merge_30 branch based on development * force-merge release_30 to development_merge_30 and push with conflicts still included * send in PRs to development_merge_30 to resolve merge conflicts as we get through them * once all conflicts are gone, merge development_merge_30 into development # Conflicts: # .travis.yml # CI/travis.linux.before_install.sh # CI/travis.linux.install.sh # CMakeLists.txt # src/ActionUnit.h # src/CMakeLists.txt # src/EAction.h # src/Host.cpp # src/Host.h # src/T2DMap.cpp # src/T2DMap.h # src/TAlias.cpp # src/TAlias.h # src/TAstar.h # src/TBuffer.cpp # src/TBuffer.h # src/TConsole.cpp # src/TConsole.h # src/TEasyButtonBar.cpp # src/TEvent.h # src/TFlipButton.h # src/TLuaInterpreter.cpp # src/TLuaInterpreter.h # src/TMap.cpp # src/TMap.h # src/TRoom.cpp # src/TRoom.h # src/TRoomDB.cpp # src/TTextEdit.cpp # src/TTextEdit.h # src/TTimer.cpp # src/TTimer.h # src/TTrigger.cpp # src/Tree.h # src/XMLexport.cpp # src/XMLimport.cpp # src/XMLimport.h # src/ctelnet.cpp # src/ctelnet.h # src/dlgConnectionProfiles.cpp # src/dlgMapper.h # src/dlgProfilePreferences.cpp # src/dlgTriggerEditor.cpp # src/dlgTriggerEditor.h # src/glwidget.h # src/mudlet-lua/genDoc.sh # src/mudlet-lua/lua/GUIUtils.lua # src/mudlet-lua/tests/GUIUtils.lua # src/mudlet.cpp # src/mudlet.h # src/src.pro # src/ui/main_window.ui # src/ui/profile_preferences.ui
2017-03-27 08:06:47 +02:00
continue;
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
}
Infrastructure: make TRoom coordinates private (#7539) #### Summary of PR Changes/Additions Makes the coordinate members of the `TRoom` class private so that access to them can be tracked via methods to set and get them. #### Motivation for Adding to Mudlet This is so that the setters can then subsequently include any extra code that needs to be aware when the room is moved. I intend to improve the detection of rooms being placed in the same position but realised this would be a good preliminary step. #### Additional Information (related issues, discussions, etc.) Removes some dead code setting but not using `(int) quads` and `(int) verts` in `(void) GLWidget::paintGL()` Also using the mouse to drag and thus move selected rooms when those rooms were on different levels would squash them all down to be on the same z-coordinate as the "highlighted centre of the selection" room. This is not as helpful it might seem and instead increased the likelihood of causing room collisions - so now each room will retain it's z coordinate if it is not on the same level as the centre of the multiple room selection. Also move code that likely needs to be run whenever rooms are added/removed/moved within an area to a common block of code (`(void) TArea::clean()`) to help keep things DRY. I intend to put code to update a per area record of rooms that are in the same place within that block in the future - so that the record can be reused without having to be repeatedly recalculated, especially in the paint event for the 2D mapper. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2024-12-09 14:29:13 +00:00
pT->setCoordinates(attributes().value(qsl("x")).toString().toInt(), attributes().value(qsl("y")).toString().toInt(), attributes().value(qsl("z")).toString().toInt());
Enhance: fix map downloading code, add manual XML map importing (#329) A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) a count of 100's of rooms processed. This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. However errors for the XML map file importing process as initiated from the Lua command are generally returned to that command rather than plastered onto the main profile console. Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 08:03:42 +01:00
continue;
} else if (name() == qsl("features")) {
readRoomFeatures(pT);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else if (Q_UNLIKELY(name().isEmpty())) {
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
continue;
}
if (isEndElement() && name() == qsl("room")) {
2010-08-25 00:41:43 +02:00
break;
}
}
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (pT->id > 0) {
if (++(*roomCount) % 100 == 0) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->reportStringToProgressDialog(tr("Parsing room data [count: %1]...").arg(*roomCount));
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
areamRoomMultiHash.insert(pT->area, pT->id);
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
// We are loading a map so can make some optimisation by setting the
// third argument as true:
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->mpMap->mpRoomDB->addRoom(pT->id, pT, true);
mMaxRoomId = qMax(mMaxRoomId, pT->id); // Wasn't used but now maintains max Room Id
} else {
2010-08-25 00:41:43 +02:00
delete pT;
Enhance: fix map downloading code, add manual XML map importing (#326) * Enhance: fix map downloading code, add manual XML map importing A recent move by I.R.E. to using SSL for their public MUD map URLs broke the ability for Mudlet to download those XML format files. This commit addresses this issue (as mentioned in, but not the original problem referred to in https://bugs.launchpad.net/mudlet/+bug/1427364) the revision to the code does now use "https://www.<MUD URL>/maps/map.xml" as a default name for the I.R.E. MUDS - however the method that initiates the download which was moved to TMap class from the dlgMapper one (see below) is now: (bool) TMap::downloadMap( const QString * remoteUrl = Q_NULLPTR, const QString * localFileName = Q_NULLPTR ) which if not supplied with any arguments behaves as before. However the remoteUrl argument may be given as a full QString including the scheme (the bit of the URL at the beginning before the ':') to override that and a second argument may be used to provide a different name to use for the local file name which if is a RELATIVE pathFileName will be resolved in relation to the profile directory. At present no use is made of this additional functionality but it may be useful for use with other MUDs if they should choose to provide XML map files with other remote locations and scripts using a different local filename. As a long-standing thing that needed doing I have finally provided a means to import a map XML file that - for instance - has already been download. It had been noted that there was no way to read those I.R.E. map files even if they had been obtained from a web browser able to correctly handle https: URLs - now both the TLuaInterpreter::loadMap() and the dlgProfilePreference "loadMap" button {NOT the IRE only "map download" one} will both handle files ending in ".xml" (not case sensitive so it'll work MacOS platforms as well!} For the loadMap case it will be necessary to change the filetype filter on the File Selection dialog to select "xml" files. During testing it became clear to me that it was possible to try and read one or more XML files via several mechanisms simultaneously with "unhelpful" consequences. As well as hitting the dlgProfilePreferences IRE "map download" multiple times, the TLuaInterpreter::loadMap() does NOT block until the map has been loaded and as the import time {running of XMLinport::readPackage(...)} is of significant duration for a large map (a debug, without optimisation, build on my 1.8GHz Quad-core took over two minutes to process the current Achaea map file) it is very possible to get conditions where the same profile will try to run XMLinport::readPackage(...) asynchronously - given that a profile only supports ONE map at a time it was necessary to fit a QMutex to prevent the part of the XMLinport class relating to XML Map files being called from different places in the map related code. This means that if a map download is started further downloads and any local map imports will fail until that first download has completed or aborted. Similarly a local import will prevent a download being started. As a side effect this cures: https://bugs.launchpad.net/mudlet/+bug/852861 - "Map download button starts another download thread if one is already going" The previous XML import code was not adding the rooms that it parsed to the relevant TArea::rooms member - although this would be picked-up and fixed by TMap::audit() later on, this would be accompanied by an error message about every single room. The code now builds up this information while parsing the rooms' details and inserts it so that this does not cause report-able problems during the TMap::audit() execution - the data gathered also allows missing areas to be spotted so that if a room claimed to belong to an area that was not included in the preceding areas' data an unnamed area is created for it. As a consequence of the long time to actually parse an XML map file I have enhanced the progress dialog that was originally used to track the map file download. It is now retained until the file is completely imported and shows more information about the process - importantly it shows during the XMLimport::readRoom(...) the room id being processed - and THAT method is the time/cpu hog so seeing something happening during the time that Mudlet otherwise appears to hang is useful feedback even if it adds a few seconds to the overall duration (may be more than a minute). This dialog is now also used during the other routes that involve reading an XML file and there is now a bit of consistence with the on-screen messages. Whilst inspecting XMLimport class I found there was some uncertain initialisation which I have tidied up. In summary: Added: * (bool) TConsole::importMap(const QString & location) * (void) TRoomDB::setAreaRooms(const int areaId, const QSet<int> & roomIds) * image file mudlet_map_download.png used as icon for download/import progress dialog * (bool) TMap::importMap(QFile & file) * (bool) TMap::readXmlMapFile(QFile & file) * (void) TMap::slot_downloadError(QNetworkReply::NetworkError error) * (void) TMap::reportStringToProgressDialog(const QString text) * (void) TMap::reportProgressToProgressDialog(const int current, const int maximum) Revised: * (int)TLuaInterpreter::loadMap( lua_State * ) * Moved XML map download code from dlgMapper class to the TMap one: + (void) dlgMapper::downloadMap() ==> (bool) TMap::downloadMap(const QString * remoteUrl, const QString * localFileName) + (void) dlgMapper::setDownloadProgress(qint64, qint64) ==> (void) TMap::slot_setDownloadProgress(qint64,qint64) + (void) dlgMapper::cancel() ==> (void) TMap::slot_downloadCancel() + (void) dlgMapper::replyFinished(QNetworkReply *) ==> (void) TMap::slot_replyFinished(QNetworkReply *) * Enhanced download progress indication to also include parsing which can take even more time than download! * Provide means to import local XML map file * Prevent trying to import/download more than one map at a time Renamed: * (void) XMLimport::readAreaNames() ==> XMLimport::readArea() - for consistency with related functions Commented out unused: * (void) XMLimport::readUnknownRoomElement() Note the movement of the map file download code to the TMap class does require making the latter a class with the Q_OBJECT macro (which removes the need for Q_DECLARE_TR_FUNCTIONS as a side-effect!) - though as another side-effect the TMap header needed a boost name specifier added to one identifier as that identifier ("property") exists in both boost and QObject classes!!! YOU MAY NEED TO RUN QMAKE ON THE PROJECT IF THE BUILD SYSTEM DOES NOT PICK UP THE ADDITION OF "Q_OBJECT" TO TMAP CLASS. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: Include missing #include, remove unused return value The absence of this was causing build errors on the Travis C.I. platform! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * BugFix: move TMap.h to mudlet_MOC_HDRS to fix CMake build issue As we have made TMap inherit from QOject - to have signal/slot functionality that class needs to be run through Qt's MOC - and to do that with the CMake project/build system it needs to be included in the files included in the projects *_MOC_HDRS {and removed from the *_HDRS} variable. Also spotted a trivial error in that specifying a const return value from method is ineffective and pointless - so removed it from: TMap::retrieveMapFileStats(QString,QString *,int *,int *,int *,int *) Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: clean up TMap initialisation/clearing actions Now restores the customEnvColors set up on initialisation but that was cleared when the map replaced with another one that is loaded {which subsequently replaces that element anyway} or imported {which merely writes over it, replacing any matching keys}. Initialises elements that when inspected on the entry to the constructor proper previously were not being set to a consistent value {booleans/ints/floats}. NOTE: This will now clear the map user data member when the map is cleared if the date is required to be saved when one map is loaded OR IMPORTED over an existing one then the data will need to be saved outside of the map - as is already need for areas and rooms user data! Also comment out or remove unused members/methods: * (void) TMap::getConnectedNodesGreaterThanX(int, int) * (void) TMap::getConnectedNodesSmallerThanX(int, int) * (void) TMap::getConnectedNodesGreaterThanY(int, int) * (void) TMap::getConnectedNodesSmallerThanY(int, int) * (void) TMap::astBreitenAnpassung(int, int) * (void) TMap::astHoehenAnpassung(int, int) * (void) TMap::exportMapToDatabase() * (void) TMap::importMapFromDatabase() * (QVector3D) TMap::span * (int) TMap::mViewArea * (QMap<QString, int>) TMap::pixNameTable * (QMap<int, QPixmap>) TMap::pixTable * (bool) TMap::isToDisplayAuditErrorsToConsole Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * ImplimentationFixes: activate a valid optimisation & remove redundant code Adding a true as a non-default 3rd argument to TRoomDB::addRoom(...) call in XMLimport::readRoom(...) enables a significant optimisation (skips a computationally expensive step when ADDING a room to new map) which dramatically reduces the time to parse an XML map file. It also pointed to the fact that the TRoomDB::entranceMap was already correctly being handled and didn't need to be regenerated in XMLimport::readRoom(...) so the code that was added in a previous commit was redundant and could be removed. A code error in TMap::slot_setDownloadProgress(...) that caused an issue that a reviewer found on test has been fixed - the total download filesize that was being sent by the Qt system signal that is connected to this slot was a -1 value (as IS DOCUMENTED) when the Qt system does NOT know the size of a QNetworkReply in advance of reaching the end of the download was incorrectly handled in a previous commit in this change set. Also found during testing that there is no need for an error message for the QNetworkReply::OperationCanceledError case in TMap::slot_replayFinished(...) as it is already handled in the TMap::slot_downloadCancel() slot. Changed the text put up onto the progress widget during the XML room parsing to be a room count - which is likely more useful and to only do it for every hundredth room - which reduces any delay "wasted" in writing to the display - combined, the effects seem satisfactory IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: provide error messages for TLuaInterpreter::loadMap(...) Errors for the XML map file importing process as initiated from the Lua command should be returned to that command rather than plastered onto the main profile console - this commit attempts to perform that effect. In testing found that there was no error handling for failure to find or open the nominated file so messages for that have been added as well. Due to the previous program logic the action of creating a mapper widget using the main toolbar button automatically loaded the "default" (the newest Mudlet Map file format file from the currently active profile's map sub-directory). Under some previous situations it looked as though a map might be loaded twice as mudlet::slot_mapper() was called both directly and via signal/slot action. These were resolved by turning that slot into a wrapper that now calls the body of code formerly within to a new method mudlet::createMapper( bool isToLoadDefaultMapFile = true ) with a the default value as an argument. This allows other usages of the body of code to be called directly with a suitable argument, which for the TConsole::loadMap() & TConsole::importMap() and the dlgProfilePreferences::downloadMap() cases is false as they are all do not want the "default" map! Also: * spotted a word "area" missing from an advisory text in TRoom::auditRooms(...). Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Tweak: fix minor bug, correct a spelling, undo a few capitalisations Under certain, unanticipated (error with no error message) conditions TLuaInterpreter::loadMap(...) would push both a nil and then a false value onto the stack for return {wrong} but only indicate one value {correct}. The textual matters were found during peer review. off-by: Stephen Lyons <slysven@virginmedia.com>
2016-10-13 09:18:48 +01:00
}
2010-01-22 01:45:34 +01:00
}
void XMLimport::readUnknownMapElement()
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2010-01-22 01:45:34 +01:00
readNext();
2010-08-25 00:41:43 +02:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
2010-08-25 00:41:43 +02:00
break;
}
if (isStartElement()) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownMapElement();
2010-08-25 00:41:43 +02:00
}
}
}
// returns the type of item and ID of the first (root) element
std::pair<EditorViewType, int> XMLimport::readPackage()
2009-02-06 03:39:14 +01:00
{
EditorViewType objectType = EditorViewType::cmUnknownView;
int rootItemID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2009-02-06 03:39:14 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("HostPackage")) {
readHostPackage();
} else if (name() == qsl("TriggerPackage")) {
objectType = EditorViewType::cmTriggerView;
rootItemID = readTriggerPackage();
} else if (name() == qsl("TimerPackage")) {
objectType = EditorViewType::cmTimerView;
rootItemID = readTimerPackage();
} else if (name() == qsl("AliasPackage")) {
objectType = EditorViewType::cmAliasView;
rootItemID = readAliasPackage();
} else if (name() == qsl("ActionPackage")) {
objectType = EditorViewType::cmActionView;
rootItemID = readActionPackage();
} else if (name() == qsl("ScriptPackage")) {
objectType = EditorViewType::cmScriptView;
rootItemID = readScriptPackage();
} else if (name() == qsl("KeyPackage")) {
objectType = EditorViewType::cmKeysView;
rootItemID = readKeyPackage();
} else if (name() == qsl("HelpPackage")) {
readHelpPackage();
} else if (name() == qsl("VariablePackage")) {
objectType = EditorViewType::cmVarsView;
2013-06-09 12:25:52 -04:00
readVariablePackage();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("MudletPackage"));
2009-02-06 03:39:14 +01:00
}
}
}
return {objectType, rootItemID};
2009-02-06 03:39:14 +01:00
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
void XMLimport::readHelpPackage()
{
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("helpURL")) {
const QString contents = readElementText();
mpHost->moduleHelp[mPackageName].insert("helpURL", contents);
}
}
}
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
// Will be on a startElement on entry, and on the matching endElement
// at exit:
void XMLimport::readUnknownElement(const QString& what)
2009-02-06 03:39:14 +01:00
{
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
if (!atEnd()) {
qDebug().nospace().noquote() << "XMLimport::readUnknownElement(\"" << what << "\") ERROR - UNKNOWN Package Element name: \"" << name().toString() << "\".";
qDebug().nospace().noquote() << " This is at byte offset: " << characterOffset() << ", which is (line:column): " << lineNumber() << ":" << columnNumber() << ".";
#if !defined(QT_STRICT_ITERATORS)
if (attributes().isEmpty()) {
qDebug().nospace().noquote() << " It has no attributes.";
} else {
// This can fail if QT_STRICT_ITERATORS is defined.
// See https://bugreports.qt.io/browse/QTBUG-45368
QVectorIterator<QXmlStreamAttribute> itAttribute(attributes());
qDebug().nospace().noquote() << " It has the following attributes:";
while (itAttribute.hasNext()) {
const auto attribute = itAttribute.next();
qDebug().nospace().noquote() << " name: \"" << attribute.name() << "\", value: \"" << attribute.value() << "\".";
}
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
#endif
// The argument to readElementText(...) is required otherwise it stops
// if a child element is encountered, the third alternative
// "IncludeChildElements" is not so helpful as it might seem as it only
// includes some of the intervening content from sub-elements. As it is
// this should advance the current position to the EndElement of the
// unexpected startElement:
qDebug().nospace().noquote() << " The (text) content is: \"" << readElementText(QXmlStreamReader::SkipChildElements) << "\"";
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
void XMLimport::readHostPackage()
{
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("Host")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readHost(mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("HostPackage"));
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
}
}
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
void XMLimport::readHost(Host* pHost)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
{
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
// This is an inline helper function to get a boolean value from a legacy attribute
// or return a default value. It also allows for inverting the result which is useful
// for attributes that have been negated in the past (e.g., mFORCE_MXP_NEGOTIATION_OFF
// which is now mEnableMXP, mFORCE_CHARSET_NEGOTIATION_OFF which is now mEnableCHARSET,
// and forceNewEnvironNegotiationOff which is now mEnableNEWENVIRON).
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
auto getBoolValueFromLegacyAttributeOrDefault = [&](const QString& legacyAttribute, const bool defaultsTo, bool invert = false) -> bool {
if (attributes().hasAttribute(legacyAttribute)) {
bool value = attributes().value(legacyAttribute) == YES;
return invert ? !value : value;
}
return defaultsTo;
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
};
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
auto setBoolAttributeWithDefault = [&](const QString& attribute, bool& target, const bool defaultsTo) {
target = attributes().hasAttribute(attribute) ? attributes().value(attribute) == YES : defaultsTo;
};
auto setBoolAttribute = [&](const QString& attribute, bool& target) {
target = attributes().value(attribute) == YES;
};
setBoolAttributeWithDefault(qsl("announceIncomingText"), pHost->mAnnounceIncomingText, true);
setBoolAttributeWithDefault(qsl("advertiseScreenReader"), pHost->mAdvertiseScreenReader, false);
improve: OSC 8 hyperlink handling, and a setting to turn it off (#9731) #### Brief overview of PR changes/additions - Hardens how OSC 8 link payloads and link text are handled before they are run or displayed; link commands are no longer built by string-formatting remote text into Lua source. - Adds a per-profile setting (General → Game protocols) to turn OSC 8 hyperlinks off, which also reports `0` for every `OSC_HYPERLINKS*` NEW-ENVIRON variable and sends an INFO update if toggled mid-session. - Fixes `selected=` callbacks on `send:` links, which never fired, and keeps emoji and Persian/Arabic/Indic text intact in tooltips and menu labels. #### Motivation for adding to Mudlet Inspired by [conversation](https://discord.com/channels/279748146316312576/1416447642472284261/1535109010066251890) on the MUD Discord and updates to terminal emulators. OSC 8 sequences arrive from the game server — and often from another player whose say/tell text the server relays — so they have to be treated as untrusted input rather than as content the user chose to load. #### Other info (issues closed, discussion etc) New unit tests: `LuaLiteralTest` (28 cases, including an exhaustive sweep over the bracket alphabet, each evaluated in a real Lua 5.1 state) and `UntrustedTextTest` (26 cases covering emoji sequences, non-Latin shaping and the two sanitization policies). There is no automated NEW-ENVIRON coverage anywhere in the repo, so that path was verified manually against a live server instead. **Test case:** 1. `say !osc8-docs` — every documented feature still works. 2. Send a link whose command ends in `]`, e.g. `send:say [OOC]` — clicking sends the literal text (previously the click silently did nothing). 3. Settings → General → Game protocols → uncheck "Enable OSC 8 hyperlinks from the server" — links stop rendering and the server is told without a reconnect; re-check and they return. 4. Send a tooltip or menu label containing a multi-part emoji such as 👨‍🍳 — it renders normally, not as its component parts. --------- Signed-off-by: Michael Conley <sousesider@gmail.com>
2026-08-08 04:09:32 -04:00
setBoolAttributeWithDefault(qsl("enableOSC8Hyperlinks"), pHost->mEnableOSC8Hyperlinks, true);
Add: Closed Captioning for Media (#7838) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions To improve accessibility for hearing impaired within the Media handling in Mudlet (or those who just want sound off while they game), this enhancement adds a closed captioning feature and the following optional parameter implemented in the GMCP syntax for `Client.Media.Play` and Lua API functions `playSoundFile`, `playMusicFile`, `playVideoFile` for playing media: * `caption`: A caption-friendly textual representation of the sound, such as onomatopoeia or sound cues (e.g., *thunderclap*, *blacksmith hammering*). Inspired by [Captioning Key – Sound Effects and Music](https://dcmp.org/learn/602-captioning-key---sound-effects-and-music%7CDCMP). ----- To enable the closed caption capability in Mudlet, a checkbox was added into the Settings->Accessibility menu: <img width="626" alt="Screenshot 2025-05-11 at 4 01 40 PM" src="https://github.com/user-attachments/assets/d8b68c79-ed4d-4b80-b4c1-4c3ada8326e2" /> ----- Here is the outcome [in brackets] where a caption is not set (the cow) and where a caption is set (rugby club): <img width="821" alt="Screenshot 2025-05-11 at 9 57 55 AM" src="https://github.com/user-attachments/assets/026fa694-1bb7-46b8-837b-78f9d17b1d23" /> #### Motivation for adding to Mudlet Discussions with @RahjIII who authors the LociTerm client. #### Other info (issues closed, discussion etc) Aligns with update 1.0.3 for the [Mud Client Media Protocol](https://wiki.mudlet.org/w/Standards:MUD_Client_Media_Protocol).
2025-05-13 05:55:43 -04:00
setBoolAttributeWithDefault(qsl("enableClosedCaption"), pHost->mEnableClosedCaption, false);
Improve: New Environ and MNES Support (#7058) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions To enhance player experience and simplify the onboarding of accessible users by sharing more client supported detail, support for two protocols are requested to be added to Mudlet. In particular, knowing through information exchange that a client supports UTF-8, TRUECOLOR, and an opt-in indicator of screen reader use, may ease initial setup and increase the stay rate for new gaming community members. [Mudlet Area 51 Reference](https://wiki.mudlet.org/w/Area_51#NEW-ENVIRON.2C_PR_.237058) ##### Implemented [Telnet New-Environ Option](https://www.rfc-editor.org/rfc/rfc1572.txt) (39): * Added `Force NEW_ENVIRON Negotiation Off` to the Special Options menu * Negotiate `NEW_ENVIRON` when prompted by the server * Enable servers to request `SEND` updates, individually or in bulk for: * Well-know variables: ~~`SYSTEMTYPE`, `USER`~~ * User variables: `CHARSET`, `CLIENT_NAME`, `CLIENT_VERSION`, `MTTS`, `TERMINAL_TYPE`, `IPADDRESS`, `ANSI`, `VT100`, `256_COLORS`, `MOUSE_TRACKING`, `UTF-8`, `OSC_COLOR_PALETTE`, `SCREEN_READER`, `PROXY`, `TRUECOLOR`, `TLS`, ~~`LANGUAGE`, `FONT`, `FONT_SIZE`,~~ `WORD_WRAP` * Enable servers to receive `INFO` updates for known variables, previously replied with an `IS` and not undefined: * `CHARSET` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `MTTS` changes status (see CHARSET and SCREEN_READER) * `UTF-8` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `SCREEN_READER` changes status (Accessibility menu) * ~~`LANGUAGE` changes (General menu)~~ * ~~`FONT` and `FONT_SIZE` changes (Main display menu)~~ * `WORD_WRAP` changes (Main display menu) ##### Implemented [Mud New Environment Standard](https://tintin.mudhalla.net/protocols/mnes/) (39 as MNES): * Added `Enable MNES` to the General menu (defaults disabled) * Removed `Force MTTS Negotiation Off` from the Special Options menu * Added `Enable MTTS` to the General menu (defaults enabled, still) * Negotiate `NEW_ENVIRON (MNES)` when prompted by the server * Enable servers to request `SEND` updates, individually or in bulk for: * MNES variables: `CHARSET`, `CLIENT_NAME`, `CLIENT_VERSION`, `MTTS`, `TERMINAL_TYPE`, `IPADDRESS` * Enable servers to receive `INFO` updates for known variables, previously replied with an `IS` and not undefined: * `CHARSET` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `MTTS` changes status (General menu, Accessibility menu, and see CHARSET) Example of **Telnet New-Environ Option** requests from game servers: ``` IAC SB NEW_ENVIRON SEND VAR "UTF-8" IAC SE // Request one USERVAR variable IAC SB NEW_ENVIRON SEND USERVAR "CHARSET" VAR "UTF-8" IAC SE // Request multiple variables IAC SB NEW_ENVIRON SEND "CHARSET" USERVAR IAC SE // Request CHARSET and all of the well-known USERVAR variables (see a duplicate CHARSET, this is per the RFC) IAC SB NEW_ENVIRON SEND USERVAR IAC SE // Request all the USERVAR variables (a large list like above) IAC SB NEW_ENVIRON SEND VAR USERVAR IAC SE // Request all the variables IAC SB NEW_ENVIRON SEND IAC SE // Request all the variables ``` High level example of **Telnet New-Environ Option** data from Mudlet: ``` VAR `SYSTEMTYPE` VAL `MACOS` VAR `USER` VAL `tamarindo` USERVAR `256_COLORS` VAL `1` USERVAR `ANSI` VAL `1` USERVAR `CHARSET` VAL `UTF-8` USERVAR `CLIENT_NAME` VAL `MUDLET` USERVAR `CLIENT_VERSION` VAL `4/17/2-DEV` USERVAR `MTTS` VAL `2349` USERVAR `OSC_COLOR_PALETTE` VAL `1` USERVAR `SCREEN_READER` VAL `0` USERVAR `TERMINAL_TYPE` VAL `ANSI-TRUECOLOR` USERVAR `TLS` VAL `1` USERVAR `TRUECOLOR` VAL `1` USERVAR `UTF-8` VAL `1` USERVAR `VT100` VAL `0` USERVAR `WORD_WRAP` VAL `100` ``` Example of **Mud New Environment Standard** requests from game servers: ``` IAC SB NEW_ENVIRON SEND VAR "CHARSET" IAC SE // Request one variable IAC SB NEW_ENVIRON SEND VAR "CHARSET" VAR "MTTS" IAC SE // Request more than one variable IAC SB NEW_ENVIRON SEND VAR IAC SE // Request all variables IAC SB NEW_ENVIRON SEND IAC SE // Request all variables ``` High level example of **Mud New Environment Standard** data from Mudlet: ``` VAR `CHARSET` VAL `UTF-8` VAR `CLIENT_NAME` VAL `MUDLET` VAR `CLIENT_VERSION` VAL `4/17/2-DEV` VAR `MTTS` VAL `2861` VAR `TERMINAL_TYPE` VAL `ANSI-TRUECOLOR` ``` #### Motivation for adding to Mudlet Get updates that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, SCREEN_READER) #### Other info (issues closed, discussion etc) [Mudlet Area 51 Reference](https://wiki.mudlet.org/w/Area_51#NEW-ENVIRON.2C_PR_.237058) --------- Co-authored-by: Marco Fontani <mfontani@cpan.org> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2024-01-05 09:31:56 -05:00
setBoolAttributeWithDefault(qsl("mEnableMTTS"), pHost->mEnableMTTS, true);
setBoolAttributeWithDefault(qsl("mEnableMNES"), pHost->mEnableMNES, false);
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
setBoolAttributeWithDefault(qsl("mEnableMXP"), pHost->mEnableMXP, getBoolValueFromLegacyAttributeOrDefault(qsl("mFORCE_MXP_NEGOTIATION_OFF"), true, true));
setBoolAttributeWithDefault(qsl("mEnableNAWS"), pHost->mEnableNAWS, true);
setBoolAttributeWithDefault(qsl("mUndoServerWrap"), pHost->mUndoServerWrap, false);
setBoolAttributeWithDefault(qsl("mServerWrapHintShown"), pHost->mServerWrapHintShown, false);
setBoolAttributeWithDefault(qsl("mEnableCHARSET"), pHost->mEnableCHARSET, getBoolValueFromLegacyAttributeOrDefault(qsl("mFORCE_CHARSET_NEGOTIATION_OFF"), true, true));
setBoolAttributeWithDefault(qsl("mEnableNEWENVIRON"), pHost->mEnableNEWENVIRON, getBoolValueFromLegacyAttributeOrDefault(qsl("forceNewEnvironNegotiationOff"), true, true));
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("autoClearCommandLineAfterSend"), pHost->mAutoClearCommandLineAfterSend);
Improve: Enhanced password handling with smart restoration and user options (#8213) #### Brief overview of PR changes/additions Enhances existing command preservation by preventing restoration when users type during password entry, plus adds an optional setting to disable password masking entirely for users who prefer it. #### Motivation for adding to Mudlet Builds upon existing command preservation (PR #7924) to handle edge cases where the previous implementation could overwrite passwords if users typed during echo suppression. #### Other info (issues closed, discussion etc) May close #8127 Key enhancements: - Smart restoration logic prevents overwriting user input during password mode - Optional password masking disable setting for trusted environments - Improved debug messaging for troubleshooting Small refinements that make the existing preservation feature more robust. --- Disable password masking feature: <img width="2174" height="846" alt="Screenshot 2025-09-13 at 10 11 21 AM" src="https://github.com/user-attachments/assets/698e4394-a025-433b-87b3-97bfdea1576e" /> --- Disable password masking enable and disable https://github.com/user-attachments/assets/2cc33216-665a-43b4-a957-97a1f0a28771 --- Preserving text sent before an auto-login (still works) https://github.com/user-attachments/assets/2b7c0029-d3dc-43cf-ab61-69d982993deb --- There is presumed to be one more case where the end-user has their own Lua script for password entry outside the auto-login where this change should preserve their pretyped but unsent text.
2025-10-19 07:43:58 -04:00
setBoolAttributeWithDefault(qsl("disablePasswordMasking"), pHost->mDisablePasswordMasking, false);
Fix: Show sent commands -> Always / Script Controlled / Never (#7881) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR enhances the "Show the text you sent" setting from a simple boolean checkbox to a tri-state system, providing more granular control over command echoing behavior while maintaining complete backward compatibility. **New Options:** - **Never**: Commands are never shown on screen, regardless of script settings - **Script controlled** (Default): Scripts can control visibility using `send(cmd, true/false)` - **Always**: Commands are always shown on screen, regardless of script settings **Key Changes:** - Replaced `bool mPrintCommand` with `enum class CommandEchoMode` (Never=0, ScriptControl=1, Always=2) - Enhanced `send()` function logic to respect the new tri-state mode - Updated UI from checkbox to combo box with descriptive tooltips - Implemented automatic migration from legacy boolean settings - Enhanced Lua API with dual-mode backward compatibility ![Screenshot 2025-07-05 at 10 56 00 PM](https://github.com/user-attachments/assets/769f30c8-7159-4c36-b48b-2cbaf866c636) #### Motivation for adding to Mudlet Resolves the inconsistent behavior reported in #6919 where `send(cmd, false)` could suppress echo regardless of the global setting, but `send(cmd, true)` could not show text if the global setting was disabled. **Problems Solved:** 1. **API Consistency**: Both `true` and `false` parameters to `send()` now properly override global settings when appropriate 2. **User Control**: Users can choose between three clear modes instead of confusing boolean behavior 3. **Script Safety**: Packages can provide critical feedback to users even when global echo is disabled 4. **Backward Compatibility**: All existing scripts and profiles continue to work unchanged **Use Cases Addressed:** - Users who never want to see commands (accessibility, clean interface) - Users who want full script control (current behavior, new default) - Users who always want to see commands (debugging, transparency) - Package authors who need to ensure important messages are visible #### Other info (issues closed, discussion etc) **Closes:** #6919 **Backward Compatibility Strategy:** - Legacy profile files: `printCommand="yes"` → ScriptControl, `printCommand="no"` → Never - Legacy Lua API: `getConfig("showSentText")` returns boolean (true/false) for existing scripts - Enhanced Lua API: `getConfig("showSentText", true)` returns string ("never"/"script"/"always") for new scripts - Universal `setConfig()`: Accepts both boolean and string values with automatic conversion **Migration Path:** - Existing scripts work unchanged - no breaking changes - Profile settings automatically converted on load using `getBoolValueFromLegacyAttributeOrDefault` - XML export includes both new and legacy attributes for compatibility **Implementation Details:** - Uses existing `getBoolValueFromLegacyAttributeOrDefault` helper for seamless profile migration - Maintains all existing `send()` behavior in ScriptControl mode (new default) - Command line echo logic updated to respect tri-state mode - Complete test coverage for all three modes and migration scenarios **Testing:** - All existing functionality preserved and tested - New tri-state behavior verified for each mode - Legacy profile migration tested with real profile files - Lua API backward compatibility confirmed with existing script patterns This hybrid approach addresses all concerns raised in the original PR discussion while providing a clear upgrade path that satisfies both user control advocates and script compatibility requirements. --- ### Show sent commands: Never | Command | Displays | | --- | --- | | `send("smile", true)` | You smile 😄 | | `send("smile", false)` | You smile 😄 | ### Show sent commands: Script controlled | Command | Displays | | --- | --- | | `send("smile", true)` | smile | | | You smile 😄 | | `send("smile", false)` | You smile 😄 | ### Show sent commands: Always | Command | Displays | | --- | --- | | `send("smile", true)` | smile | | | You smile 😄 | | `send("smile", false)` | smile | | | You smile 😄 | --- https://github.com/user-attachments/assets/f747329a-e9e2-4cff-b87a-333acca031ca --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-15 07:46:51 -04:00
// Handle command echo mode with backward compatibility
if (attributes().hasAttribute(qsl("commandEchoMode"))) {
// New tri-state attribute
int echoMode = attributes().value(qsl("commandEchoMode")).toInt();
pHost->mCommandEchoMode = static_cast<Host::CommandEchoMode>(qBound(0, echoMode, 2));
} else {
// Legacy boolean attribute - convert to new enum
bool legacyPrintCommand = getBoolValueFromLegacyAttributeOrDefault(qsl("printCommand"), true);
pHost->mCommandEchoMode = legacyPrintCommand ? Host::CommandEchoMode::ScriptControl : Host::CommandEchoMode::Never;
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("mUSE_FORCE_LF_AFTER_PROMPT"), pHost->mUSE_FORCE_LF_AFTER_PROMPT);
setBoolAttribute(qsl("mUSE_UNIX_EOL"), pHost->mUSE_UNIX_EOL);
setBoolAttribute(qsl("runAllKeyMatches"), pHost->getKeyUnit()->mRunAllKeyMatches);
setBoolAttribute(qsl("mNoAntiAlias"), pHost->mNoAntiAlias);
setBoolAttribute(qsl("mEchoLuaErrors"), pHost->mEchoLuaErrors);
setBoolAttribute(qsl("mRawStreamDump"), pHost->mIsNextLogFileInHtmlFormat);
setBoolAttribute(qsl("mIsLoggingTimestamps"), pHost->mIsLoggingTimestamps);
setBoolAttribute(qsl("mAlertOnNewData"), pHost->mAlertOnNewData);
setBoolAttribute(qsl("mFORCE_NO_COMPRESSION"), pHost->mFORCE_NO_COMPRESSION);
setBoolAttribute(qsl("mFORCE_GA_OFF"), pHost->mFORCE_GA_OFF);
setBoolAttribute(qsl("mEnableGMCP"), pHost->mEnableGMCP);
setBoolAttribute(qsl("mEnableMSSP"), pHost->mEnableMSSP);
Improve: New Environ and MNES Support (#7058) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions To enhance player experience and simplify the onboarding of accessible users by sharing more client supported detail, support for two protocols are requested to be added to Mudlet. In particular, knowing through information exchange that a client supports UTF-8, TRUECOLOR, and an opt-in indicator of screen reader use, may ease initial setup and increase the stay rate for new gaming community members. [Mudlet Area 51 Reference](https://wiki.mudlet.org/w/Area_51#NEW-ENVIRON.2C_PR_.237058) ##### Implemented [Telnet New-Environ Option](https://www.rfc-editor.org/rfc/rfc1572.txt) (39): * Added `Force NEW_ENVIRON Negotiation Off` to the Special Options menu * Negotiate `NEW_ENVIRON` when prompted by the server * Enable servers to request `SEND` updates, individually or in bulk for: * Well-know variables: ~~`SYSTEMTYPE`, `USER`~~ * User variables: `CHARSET`, `CLIENT_NAME`, `CLIENT_VERSION`, `MTTS`, `TERMINAL_TYPE`, `IPADDRESS`, `ANSI`, `VT100`, `256_COLORS`, `MOUSE_TRACKING`, `UTF-8`, `OSC_COLOR_PALETTE`, `SCREEN_READER`, `PROXY`, `TRUECOLOR`, `TLS`, ~~`LANGUAGE`, `FONT`, `FONT_SIZE`,~~ `WORD_WRAP` * Enable servers to receive `INFO` updates for known variables, previously replied with an `IS` and not undefined: * `CHARSET` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `MTTS` changes status (see CHARSET and SCREEN_READER) * `UTF-8` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `SCREEN_READER` changes status (Accessibility menu) * ~~`LANGUAGE` changes (General menu)~~ * ~~`FONT` and `FONT_SIZE` changes (Main display menu)~~ * `WORD_WRAP` changes (Main display menu) ##### Implemented [Mud New Environment Standard](https://tintin.mudhalla.net/protocols/mnes/) (39 as MNES): * Added `Enable MNES` to the General menu (defaults disabled) * Removed `Force MTTS Negotiation Off` from the Special Options menu * Added `Enable MTTS` to the General menu (defaults enabled, still) * Negotiate `NEW_ENVIRON (MNES)` when prompted by the server * Enable servers to request `SEND` updates, individually or in bulk for: * MNES variables: `CHARSET`, `CLIENT_NAME`, `CLIENT_VERSION`, `MTTS`, `TERMINAL_TYPE`, `IPADDRESS` * Enable servers to receive `INFO` updates for known variables, previously replied with an `IS` and not undefined: * `CHARSET` changes status (General menu or [Telnet Charset Option](https://wiki.mudlet.org/w/Manual:Supported_Protocols#Encoding)) * `MTTS` changes status (General menu, Accessibility menu, and see CHARSET) Example of **Telnet New-Environ Option** requests from game servers: ``` IAC SB NEW_ENVIRON SEND VAR "UTF-8" IAC SE // Request one USERVAR variable IAC SB NEW_ENVIRON SEND USERVAR "CHARSET" VAR "UTF-8" IAC SE // Request multiple variables IAC SB NEW_ENVIRON SEND "CHARSET" USERVAR IAC SE // Request CHARSET and all of the well-known USERVAR variables (see a duplicate CHARSET, this is per the RFC) IAC SB NEW_ENVIRON SEND USERVAR IAC SE // Request all the USERVAR variables (a large list like above) IAC SB NEW_ENVIRON SEND VAR USERVAR IAC SE // Request all the variables IAC SB NEW_ENVIRON SEND IAC SE // Request all the variables ``` High level example of **Telnet New-Environ Option** data from Mudlet: ``` VAR `SYSTEMTYPE` VAL `MACOS` VAR `USER` VAL `tamarindo` USERVAR `256_COLORS` VAL `1` USERVAR `ANSI` VAL `1` USERVAR `CHARSET` VAL `UTF-8` USERVAR `CLIENT_NAME` VAL `MUDLET` USERVAR `CLIENT_VERSION` VAL `4/17/2-DEV` USERVAR `MTTS` VAL `2349` USERVAR `OSC_COLOR_PALETTE` VAL `1` USERVAR `SCREEN_READER` VAL `0` USERVAR `TERMINAL_TYPE` VAL `ANSI-TRUECOLOR` USERVAR `TLS` VAL `1` USERVAR `TRUECOLOR` VAL `1` USERVAR `UTF-8` VAL `1` USERVAR `VT100` VAL `0` USERVAR `WORD_WRAP` VAL `100` ``` Example of **Mud New Environment Standard** requests from game servers: ``` IAC SB NEW_ENVIRON SEND VAR "CHARSET" IAC SE // Request one variable IAC SB NEW_ENVIRON SEND VAR "CHARSET" VAR "MTTS" IAC SE // Request more than one variable IAC SB NEW_ENVIRON SEND VAR IAC SE // Request all variables IAC SB NEW_ENVIRON SEND IAC SE // Request all variables ``` High level example of **Mud New Environment Standard** data from Mudlet: ``` VAR `CHARSET` VAL `UTF-8` VAR `CLIENT_NAME` VAL `MUDLET` VAR `CLIENT_VERSION` VAL `4/17/2-DEV` VAR `MTTS` VAL `2861` VAR `TERMINAL_TYPE` VAL `ANSI-TRUECOLOR` ``` #### Motivation for adding to Mudlet Get updates that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, SCREEN_READER) #### Other info (issues closed, discussion etc) [Mudlet Area 51 Reference](https://wiki.mudlet.org/w/Area_51#NEW-ENVIRON.2C_PR_.237058) --------- Co-authored-by: Marco Fontani <mfontani@cpan.org> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2024-01-05 09:31:56 -05:00
setBoolAttribute(qsl("mEnableMSDP"), pHost->mEnableMSDP);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("mEnableMSP"), pHost->mEnableMSP);
setBoolAttribute(qsl("mMapStrongHighlight"), pHost->mMapStrongHighlight);
setBoolAttribute(qsl("mEnableSpellCheck"), pHost->mEnableSpellCheck);
fix: map info "Short" always re-added on profile load (#8963) #### Brief overview of PR changes/additions - Fix map info contributors not persisting correctly across profile saves - "Short" was always re-added on load regardless of user settings - Move the default `{"Short"}` from an in-class initializer on `mMapInfoContributors` to explicit initialization for new profiles only in `loadProfile()` - Add `getMapInfo()` Lua function and `getConfig("mapInfo")` key to query map info contributor state #### Motivation for adding to Mudlet Map info checkbox settings should persist exactly as the user configured them, and scripts should be able to query which map info contributors are active. #### Other info (issues closed, discussion etc) **Root cause:** `Host.h` initialized `mMapInfoContributors` with `{"Short"}`. On profile load, XML import *inserted* saved values into this set without clearing it first, so the default "Short" survived and merged with whatever was actually saved. The `mShowInfo="no"` conditional clear only handled the empty case, not "Full only" or other combinations. **The fix** removes the in-class default (set starts empty), sets `{"Short"}` explicitly for brand-new profiles in `loadProfile()`, and removes the now-unnecessary conditional clear from `XMLimport`. Loaded profiles get exactly what was saved. **New Lua API - `getMapInfo()`:** Returns a table of all registered map info contributors mapped to their enabled/disabled state. Complements the existing `enableMapInfo()`/`disableMapInfo()` pair. ```lua -- returns e.g. { Short = true, Full = false } local info = getMapInfo() for name, enabled in pairs(info) do print(name .. " is " .. (enabled and "enabled" or "disabled")) end ``` **New `getConfig("mapInfo")` key:** Returns the currently enabled contributors as an array of strings. ```lua -- returns e.g. {"Short"} or {"Short", "Full"} or {} local enabled = getConfig("mapInfo") ``` **Test case:** 1. Open an existing profile, set map info to "Full" only (uncheck "Short"), close and reopen - verify only "Full" is checked 2. Set no checkboxes at all, close and reopen - verify none are checked 3. Create a brand-new profile - verify "Short" is enabled by default 4. Run `lua getMapInfo()` - verify it returns the correct table of contributors with their states 5. Run `lua getConfig("mapInfo")` - verify it returns the enabled contributors as an array --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Zooka <136661366+ZookaOnGit@users.noreply.github.com> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2026-03-22 13:39:57 +01:00
if (attributes().hasAttribute(QLatin1String("mShowInfo"))) {
// Old - pre Map Info versions of Mudlet (those before
// https://github.com/Mudlet/Mudlet/pull/4718) used the above
// setting to control the showing of what is now the "Full"
// map info display. So treat it as that to reproduce that
// behaviour:
if (attributes().value(qsl("mShowInfo")).toString() == YES) {
mpHost->mMapInfoContributors.insert(qsl("Full"));
}
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("mAcceptServerGUI"), pHost->mAcceptServerGUI);
setBoolAttribute(qsl("mAcceptServerMedia"), pHost->mAcceptServerMedia);
setBoolAttribute(qsl("mMapperUseAntiAlias"), pHost->mMapperUseAntiAlias);
setBoolAttribute(qsl("mMapperShowGrid"), pHost->mMapperShowGrid);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("mEditorAutoComplete"), pHost->mEditorAutoComplete);
Add: Enable Special Option for Version Number in TTYPE for Compatibility (#7888) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR addresses [#7826](https://github.com/Mudlet/Mudlet/issues/7826), where some MUD servers using KaVir’s protocol snippet [ [1](https://github.com/Xavious/MSDP_Protocol_Handler/blob/master/protocol.c) ] [ [2](https://github.com/scandum/msdp_protocol_snippet_by_kavir/blob/master/protocol.c) ] [ [3](https://github.com/halimcme/worldofpain/blob/master/protocol.cpp) ] expect both the client name and a numeric version (i.e., `MUDLET 4.19.1`) during Telnet TTYPE negotiation. This change allows users to optionally include the version number in the terminal type, restoring compatibility for the servers running this legacy script. * A `Send Mudlet version in terminal type` checkbox was added to the Special Options tab of Settings, which is disabled by default. * To streamline the process of applying the checkbox where needed, Mudlet will detect KaVir protocol snippet's standard pattern of 8 negotiations occuring in a specific order, responding with a *one-time* prompt for a user choice to automatically mark the checkbox and reconnect to obtain the 256 color setting within their game. * Also available via the Lua API: * `getConfig("versionInTTYPE")` * `setConfig("versionInTTYPE", option)` * `getConfig("promptForVersionInTTYPE")` * `setConfig("promptForVersionInTTYPE", option)` #### Motivation for adding to Mudlet To improve compatibility with MUD servers that require a version number in TTYPE for enhanced color support, without violating protocol standards. Since 2024 ([#7103](https://github.com/Mudlet/Mudlet/issues/7826)), Mudlet stopped sending the version number by default, because 1) it is not required by RFCs and 2) MTTS, New-Environ, and MNES were added to Mudlet. However, servers relying on this version information via KaVir's snippet started assuming Mudlet was version 1.0 or earlier and defaulted color support to 16 colors instead of 256-color mode. #### Other info (issues closed, discussion etc) Closes #7826. Restores expected behavior for servers using KaVir’s protocol snippet. No impact on servers that do not require the version number. --- New Special Option <img width="1010" alt="Screenshot 2025-06-02 at 8 20 02 AM" src="https://github.com/user-attachments/assets/65a78f8a-aa93-4073-ae48-fe4a59f2da60" /> --- Evidence of Appending Version Number with the Special Option <img width="969" alt="Screenshot 2025-06-02 at 8 19 40 AM" src="https://github.com/user-attachments/assets/1909af0b-bb1d-413d-ad6e-019b9942fa02" /> --- Detecting the Legacy Script and Prompting Special Option Activation <img width="1080" alt="Screenshot 2025-06-08 at 10 29 12 PM" src="https://github.com/user-attachments/assets/b84f5917-a4cd-467e-b1eb-be5087b4da3c" /> --- Confirming Application of the Special Option and Reconnecting <img width="907" alt="Screenshot 2025-06-08 at 10 29 41 PM" src="https://github.com/user-attachments/assets/3a26409a-958e-4735-bba2-5485f09045af" /> --------- Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2025-06-14 08:37:53 -04:00
setBoolAttribute(qsl("mVersionInTTYPE"), pHost->mVersionInTTYPE);
setBoolAttribute(qsl("mPromptedForVersionInTTYPE"), pHost->mPromptedForVersionInTTYPE);
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
setBoolAttribute(qsl("mPromptedForMXPProcessorOn"), pHost->mPromptedForMXPProcessorOn);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("enableTextAnalyzer"), pHost->mEnableTextAnalyzer);
setBoolAttribute(qsl("mBubbleMode"), pHost->mBubbleMode);
setBoolAttribute(qsl("mMapViewOnly"), pHost->mMapViewOnly);
setBoolAttribute(qsl("mShowRoomIDs"), pHost->mShowRoomID);
setBoolAttribute(qsl("mShowPanel"), pHost->mShowPanel);
setBoolAttribute(qsl("mShow3DView"), pHost->mShow3DView);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
setBoolAttribute(qsl("mHaveMapperScript"), pHost->mHaveMapperScript);
setBoolAttribute(qsl("mSslTsl"), pHost->mSslTsl);
setBoolAttribute(qsl("mSslIgnoreExpired"), pHost->mSslIgnoreExpired);
setBoolAttribute(qsl("mSslIgnoreSelfSigned"), pHost->mSslIgnoreSelfSigned);
setBoolAttribute(qsl("mSslIgnoreAll"), pHost->mSslIgnoreAll);
setBoolAttribute(qsl("mAskTlsAvailable"), pHost->mAskTlsAvailable);
setBoolAttribute(qsl("mUseProxy"), pHost->mUseProxy);
setBoolAttribute(qsl("f3SearchEnabled"), pHost->mF3SearchEnabled);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
Fix: Process MXP per negotiation (Part 2) (#7916) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This PR is a follow-up to #7862 and improves how Mudlet handles MXP support across old profiles, new profiles, and in-band detection scenarios: 1. Ensures the *Choose Protocols → MXP* preference is correctly defaulted to checked on first load of existing profiles that did not previously have it set (new profiles already worked). 2. Migrates the old "disable MXP" special option to uncheck the *Choose Protocols → MXP* setting for users who previously opted out. 3. Retains support for scripts using the deprecated `getConfig("specialForceMxpNegotiationOff")` and `setConfig(...)`. 4. Adds content-based MXP detection: if the MXP processor is off and tags like `<VERSION>`, `<SUPPORT>`, or `<!ELEMENT>` are detected, MXP is automatically enabled once per profile with a console notification. #### Motivation for adding to Mudlet MXP negotiation is not required by spec. Games fall into one of three categories: 1. Games that do not use MXP at all — enabling the processor may break gameplay. 2. Games that negotiate MXP — StickMUD and others using the KaVir protocol snippet work as expected. 3. Games like Lusternia — expect MXP to be processed based on user-side `CONFIG MXP ON` without negotiation. This PR improves compatibility in all three cases: - By default, MXP is off unless negotiated or enabled by the user. - When tags indicating MXP use are detected without negotiation, MXP is automatically enabled once per profile with a console message explaining what happened and how to disable it. - Prior profile settings and legacy script API usage are honored and migrated smoothly. #### Other info (issues closed, discussion etc) Fixes #7833 Related to and builds on #7862 Future idea: migrate CHARSET and NEW-ENVIRON to the protocol dropdown to simplify the UI further. --- https://github.com/user-attachments/assets/ec21db2d-89b1-404e-acff-3bae472a6e0c
2025-07-02 07:59:22 -04:00
pHost->setForceMXPProcessorOn(attributes().value(qsl("mForceMXPProcessorOn")) == YES);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->mProxyAddress = attributes().value(qsl("mProxyAddress")).toString();
if (attributes().hasAttribute(QLatin1String("mProxyPort"))) {
pHost->mProxyPort = attributes().value(qsl("mProxyPort")).toInt();
} else {
pHost->mProxyPort = 0;
}
pHost->mProxyUsername = attributes().value(qsl("mProxyUsername")).toString();
Improve: Secure credential management with system keychain integration and legacy migration (#7956) #### Brief overview of PR changes/additions This pull request implements secure credential management for Mudlet with system keychain integration and encrypted fallback storage: **Core Components:** - **CredentialManager**: High-level API for secure credential storage with QtKeychain integration - **SecureStringUtils**: Qt-based cryptographic utilities for encrypted file storage - **Legacy Migration**: Automatic detection and migration of existing plaintext passwords **Key Features:** - **System Keychain Integration**: Primary storage in macOS Keychain, Windows Credential Store, and Linux Secret Service via QtKeychain - **Encrypted File Fallback**: Qt crypto-based AES encryption for portable mode and keychain unavailability - **Seamless Migration**: Automatic detection and upgrade of legacy password storage formats - **Profile Isolation**: Per-profile encryption keys prevent cross-profile credential access - **Portable Mode Support**: Automatic detection and secure file-based storage for portable installations #### Motivation for adding to Mudlet **Security Enhancement:** - Eliminates plaintext password storage in profile XML files - Provides industry-standard system keychain integration for credential security - Implements authenticated encryption for fallback scenarios **User Experience:** - Zero configuration required - works automatically across all platforms - Seamless migration from existing plaintext passwords to secure storage - Native system integration provides familiar credential management experience **Future-Proofing:** - Extensible architecture supports additional credential types (API keys, tokens, etc.) - Robust fallback ensures functionality in all deployment scenarios - Prepares foundation for OAuth and external service integrations #### Other info (issues closed, discussion etc) **Security Architecture:** - **Keychain-First Strategy**: Prefers system keychain with automatic encrypted file fallback - **Legacy Format Detection**: Automatically migrates passwords from development branch keychain format - **Memory Security**: Secure string clearing and controlled credential lifecycle management - **Input Validation**: Path traversal protection and service name sanitization **Implementation Highlights:** - **Async Operations**: Non-blocking keychain operations with timeout protection - **Thread Safety**: Event-driven architecture prevents UI blocking and race conditions - **Comprehensive Testing**: Full test coverage for encryption, migration, and fallback scenarios - **Cross-Platform**: Unified API across Windows, macOS, and Linux with platform-specific optimizations **Version Compatibility & Migration:** - **Mudlet 4.19.x Compatibility**: Preserves existing plaintext password storage to ensure compatibility when switching between 4.19.x stable and development builds - **Mudlet 4.20.x Migration**: Post-4.20.0 release, automatic migration begins converting plaintext passwords to secure storage - **Bidirectional Safety**: Users can safely run both 4.19.x and development versions without losing access to their passwords during the transition period - **Legacy Format Support**: Automatically detects and migrates passwords from the original development branch keychain format (`service="Mudlet profile"`) to the new secure format # Credential Management Workflows ## 1. Credential Storage Strategy ```mermaid flowchart TD A[Store Password Request] --> B{Portable Mode?} B -->|Yes| C[Encrypt & Store in Profile File] B -->|No| D[Store in System Keychain] D --> E{Keychain Success?} E -->|Yes| F[Remove Encrypted Fallback File] E -->|No| G[Fallback to Encrypted File] F --> H[Success] G --> I{Encryption Success?} I -->|Yes| H I -->|No| J[Failure] C --> I classDef primary fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef decision fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef result fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class D,F primary class C,G fallback class B,E,I decision class H,J result ``` ## 2. Legacy Migration Workflow ```mermaid flowchart TD A[Retrieve Password Request] --> B[Try New Keychain Format] B --> C{Password Found?} C -->|Yes| D[Return Password] C -->|No| E[Check Legacy Keychain Format] E --> F{Legacy Found?} F -->|Yes| G[Migrate to New Format] G --> H[Store in New Format] H --> I[Remove Legacy Entry] I --> J[Return Migrated Password] F -->|No| K[Try Encrypted File] K --> L{File Found?} L -->|Yes| M[Decrypt & Return] L -->|No| N[Return Empty - No Password Stored] classDef newformat fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef legacy fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef migration fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff classDef fallback fill:#607D8B,stroke:#263238,stroke-width:2px,color:#fff classDef result fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff class B,H newformat class E,I legacy class G migration class K fallback class D,J,M,N result ``` ## 3. Cross-Platform Keychain Integration ```mermaid flowchart TD A[QtKeychain Request] --> B{Platform Detection} B -->|macOS| C[Access Keychain Services] B -->|Windows| D[Access Credential Store] B -->|Linux| E[Access Secret Service] C --> F[Store/Retrieve Credential] D --> F E --> F F --> G{Operation Success?} G -->|Yes| H[Return Result] G -->|No| I[Log Error & Fallback] I --> J[Use Encrypted File Storage] J --> K[AES Encryption with Profile Key] K --> L[Store in Profile Directory] classDef platform fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef keychain fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef crypto fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class C,D,E platform class F,H keychain class I,J fallback class K,L crypto ``` This implementation provides a comprehensive, secure, and user-friendly credential management system that seamlessly upgrades existing Mudlet installations while providing robust security for future credential storage needs. --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-17 06:44:38 -04:00
// Handle backward compatibility based on application version, not profile version
QString storedProxyPassword = attributes().value(qsl("mProxyPassword")).toString();
Improve: Secure credential management with system keychain integration and legacy migration (#7956) #### Brief overview of PR changes/additions This pull request implements secure credential management for Mudlet with system keychain integration and encrypted fallback storage: **Core Components:** - **CredentialManager**: High-level API for secure credential storage with QtKeychain integration - **SecureStringUtils**: Qt-based cryptographic utilities for encrypted file storage - **Legacy Migration**: Automatic detection and migration of existing plaintext passwords **Key Features:** - **System Keychain Integration**: Primary storage in macOS Keychain, Windows Credential Store, and Linux Secret Service via QtKeychain - **Encrypted File Fallback**: Qt crypto-based AES encryption for portable mode and keychain unavailability - **Seamless Migration**: Automatic detection and upgrade of legacy password storage formats - **Profile Isolation**: Per-profile encryption keys prevent cross-profile credential access - **Portable Mode Support**: Automatic detection and secure file-based storage for portable installations #### Motivation for adding to Mudlet **Security Enhancement:** - Eliminates plaintext password storage in profile XML files - Provides industry-standard system keychain integration for credential security - Implements authenticated encryption for fallback scenarios **User Experience:** - Zero configuration required - works automatically across all platforms - Seamless migration from existing plaintext passwords to secure storage - Native system integration provides familiar credential management experience **Future-Proofing:** - Extensible architecture supports additional credential types (API keys, tokens, etc.) - Robust fallback ensures functionality in all deployment scenarios - Prepares foundation for OAuth and external service integrations #### Other info (issues closed, discussion etc) **Security Architecture:** - **Keychain-First Strategy**: Prefers system keychain with automatic encrypted file fallback - **Legacy Format Detection**: Automatically migrates passwords from development branch keychain format - **Memory Security**: Secure string clearing and controlled credential lifecycle management - **Input Validation**: Path traversal protection and service name sanitization **Implementation Highlights:** - **Async Operations**: Non-blocking keychain operations with timeout protection - **Thread Safety**: Event-driven architecture prevents UI blocking and race conditions - **Comprehensive Testing**: Full test coverage for encryption, migration, and fallback scenarios - **Cross-Platform**: Unified API across Windows, macOS, and Linux with platform-specific optimizations **Version Compatibility & Migration:** - **Mudlet 4.19.x Compatibility**: Preserves existing plaintext password storage to ensure compatibility when switching between 4.19.x stable and development builds - **Mudlet 4.20.x Migration**: Post-4.20.0 release, automatic migration begins converting plaintext passwords to secure storage - **Bidirectional Safety**: Users can safely run both 4.19.x and development versions without losing access to their passwords during the transition period - **Legacy Format Support**: Automatically detects and migrates passwords from the original development branch keychain format (`service="Mudlet profile"`) to the new secure format # Credential Management Workflows ## 1. Credential Storage Strategy ```mermaid flowchart TD A[Store Password Request] --> B{Portable Mode?} B -->|Yes| C[Encrypt & Store in Profile File] B -->|No| D[Store in System Keychain] D --> E{Keychain Success?} E -->|Yes| F[Remove Encrypted Fallback File] E -->|No| G[Fallback to Encrypted File] F --> H[Success] G --> I{Encryption Success?} I -->|Yes| H I -->|No| J[Failure] C --> I classDef primary fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef decision fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef result fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class D,F primary class C,G fallback class B,E,I decision class H,J result ``` ## 2. Legacy Migration Workflow ```mermaid flowchart TD A[Retrieve Password Request] --> B[Try New Keychain Format] B --> C{Password Found?} C -->|Yes| D[Return Password] C -->|No| E[Check Legacy Keychain Format] E --> F{Legacy Found?} F -->|Yes| G[Migrate to New Format] G --> H[Store in New Format] H --> I[Remove Legacy Entry] I --> J[Return Migrated Password] F -->|No| K[Try Encrypted File] K --> L{File Found?} L -->|Yes| M[Decrypt & Return] L -->|No| N[Return Empty - No Password Stored] classDef newformat fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef legacy fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef migration fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff classDef fallback fill:#607D8B,stroke:#263238,stroke-width:2px,color:#fff classDef result fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff class B,H newformat class E,I legacy class G migration class K fallback class D,J,M,N result ``` ## 3. Cross-Platform Keychain Integration ```mermaid flowchart TD A[QtKeychain Request] --> B{Platform Detection} B -->|macOS| C[Access Keychain Services] B -->|Windows| D[Access Credential Store] B -->|Linux| E[Access Secret Service] C --> F[Store/Retrieve Credential] D --> F E --> F F --> G{Operation Success?} G -->|Yes| H[Return Result] G -->|No| I[Log Error & Fallback] I --> J[Use Encrypted File Storage] J --> K[AES Encryption with Profile Key] K --> L[Store in Profile Directory] classDef platform fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef keychain fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef crypto fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class C,D,E platform class F,H keychain class I,J fallback class K,L crypto ``` This implementation provides a comprehensive, secure, and user-friendly credential management system that seamlessly upgrades existing Mudlet installations while providing robust security for future credential storage needs. --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-17 06:44:38 -04:00
// For version 4.20.0+, use secure storage; for older versions, maintain plaintext in XML
// Use current application version for consistency with XMLexport behavior
const QString currentAppVersion = QString(APP_VERSION);
const QVersionNumber appVersion = QVersionNumber::fromString(currentAppVersion);
const QVersionNumber secureStorageVersion = QVersionNumber(4, 20, 0);
const bool useSecureStorage = appVersion >= secureStorageVersion;
Improve: Secure credential management with system keychain integration and legacy migration (#7956) #### Brief overview of PR changes/additions This pull request implements secure credential management for Mudlet with system keychain integration and encrypted fallback storage: **Core Components:** - **CredentialManager**: High-level API for secure credential storage with QtKeychain integration - **SecureStringUtils**: Qt-based cryptographic utilities for encrypted file storage - **Legacy Migration**: Automatic detection and migration of existing plaintext passwords **Key Features:** - **System Keychain Integration**: Primary storage in macOS Keychain, Windows Credential Store, and Linux Secret Service via QtKeychain - **Encrypted File Fallback**: Qt crypto-based AES encryption for portable mode and keychain unavailability - **Seamless Migration**: Automatic detection and upgrade of legacy password storage formats - **Profile Isolation**: Per-profile encryption keys prevent cross-profile credential access - **Portable Mode Support**: Automatic detection and secure file-based storage for portable installations #### Motivation for adding to Mudlet **Security Enhancement:** - Eliminates plaintext password storage in profile XML files - Provides industry-standard system keychain integration for credential security - Implements authenticated encryption for fallback scenarios **User Experience:** - Zero configuration required - works automatically across all platforms - Seamless migration from existing plaintext passwords to secure storage - Native system integration provides familiar credential management experience **Future-Proofing:** - Extensible architecture supports additional credential types (API keys, tokens, etc.) - Robust fallback ensures functionality in all deployment scenarios - Prepares foundation for OAuth and external service integrations #### Other info (issues closed, discussion etc) **Security Architecture:** - **Keychain-First Strategy**: Prefers system keychain with automatic encrypted file fallback - **Legacy Format Detection**: Automatically migrates passwords from development branch keychain format - **Memory Security**: Secure string clearing and controlled credential lifecycle management - **Input Validation**: Path traversal protection and service name sanitization **Implementation Highlights:** - **Async Operations**: Non-blocking keychain operations with timeout protection - **Thread Safety**: Event-driven architecture prevents UI blocking and race conditions - **Comprehensive Testing**: Full test coverage for encryption, migration, and fallback scenarios - **Cross-Platform**: Unified API across Windows, macOS, and Linux with platform-specific optimizations **Version Compatibility & Migration:** - **Mudlet 4.19.x Compatibility**: Preserves existing plaintext password storage to ensure compatibility when switching between 4.19.x stable and development builds - **Mudlet 4.20.x Migration**: Post-4.20.0 release, automatic migration begins converting plaintext passwords to secure storage - **Bidirectional Safety**: Users can safely run both 4.19.x and development versions without losing access to their passwords during the transition period - **Legacy Format Support**: Automatically detects and migrates passwords from the original development branch keychain format (`service="Mudlet profile"`) to the new secure format # Credential Management Workflows ## 1. Credential Storage Strategy ```mermaid flowchart TD A[Store Password Request] --> B{Portable Mode?} B -->|Yes| C[Encrypt & Store in Profile File] B -->|No| D[Store in System Keychain] D --> E{Keychain Success?} E -->|Yes| F[Remove Encrypted Fallback File] E -->|No| G[Fallback to Encrypted File] F --> H[Success] G --> I{Encryption Success?} I -->|Yes| H I -->|No| J[Failure] C --> I classDef primary fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef decision fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef result fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class D,F primary class C,G fallback class B,E,I decision class H,J result ``` ## 2. Legacy Migration Workflow ```mermaid flowchart TD A[Retrieve Password Request] --> B[Try New Keychain Format] B --> C{Password Found?} C -->|Yes| D[Return Password] C -->|No| E[Check Legacy Keychain Format] E --> F{Legacy Found?} F -->|Yes| G[Migrate to New Format] G --> H[Store in New Format] H --> I[Remove Legacy Entry] I --> J[Return Migrated Password] F -->|No| K[Try Encrypted File] K --> L{File Found?} L -->|Yes| M[Decrypt & Return] L -->|No| N[Return Empty - No Password Stored] classDef newformat fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef legacy fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef migration fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff classDef fallback fill:#607D8B,stroke:#263238,stroke-width:2px,color:#fff classDef result fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff class B,H newformat class E,I legacy class G migration class K fallback class D,J,M,N result ``` ## 3. Cross-Platform Keychain Integration ```mermaid flowchart TD A[QtKeychain Request] --> B{Platform Detection} B -->|macOS| C[Access Keychain Services] B -->|Windows| D[Access Credential Store] B -->|Linux| E[Access Secret Service] C --> F[Store/Retrieve Credential] D --> F E --> F F --> G{Operation Success?} G -->|Yes| H[Return Result] G -->|No| I[Log Error & Fallback] I --> J[Use Encrypted File Storage] J --> K[AES Encryption with Profile Key] K --> L[Store in Profile Directory] classDef platform fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff classDef keychain fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#000 classDef fallback fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#000 classDef crypto fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff class C,D,E platform class F,H keychain class I,J fallback class K,L crypto ``` This implementation provides a comprehensive, secure, and user-friendly credential management system that seamlessly upgrades existing Mudlet installations while providing robust security for future credential storage needs. --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-17 06:44:38 -04:00
if (!storedProxyPassword.isEmpty()) {
if (useSecureStorage) {
// Modern application: migrate plaintext password to secure storage and clear from XML
CredentialManager::storeCredential(pHost->getName(), "proxy", storedProxyPassword);
pHost->mProxyPassword = storedProxyPassword;
SecureStringUtils::secureStringClear(storedProxyPassword); // Clear after migration
} else {
// Legacy application: keep plaintext password for backward compatibility
pHost->mProxyPassword = storedProxyPassword;
}
} else if (useSecureStorage) {
// Modern application: load from secure storage if available
pHost->mProxyPassword = CredentialManager::retrieveCredential(pHost->getName(), "proxy");
}
pHost->set_USE_IRE_DRIVER_BUGFIX(attributes().value(qsl("USE_IRE_DRIVER_BUGFIX")) == YES);
pHost->mHighlightHistory = readDefaultTrueBool(qsl("HighlightHistory"));
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->mLogDir = attributes().value(qsl("logDirectory")).toString();
pHost->mFORCE_SAVE_ON_EXIT = readDefaultTrueBool(qsl("mFORCE_SAVE_ON_EXIT"));
const bool enableUserDictionary = attributes().value(qsl("mEnableUserDictionary")) == YES;
const bool useSharedDictionary = attributes().value(qsl("mUseSharedDictionary")) == YES;
pHost->setUserDictionaryOptions(enableUserDictionary, useSharedDictionary);
pHost->mMapperShowRoomBorders = readDefaultTrueBool(qsl("mMapperShowRoomBorders"));
pHost->mEditorTheme = attributes().value(QLatin1String("mEditorTheme")).toString();
pHost->mEditorThemeFile = attributes().value(QLatin1String("mEditorThemeFile")).toString();
if (pHost->mEditorTheme.isEmpty() || pHost->mEditorThemeFile.isEmpty()) {
pHost->mEditorTheme = qsl("Mudlet");
pHost->mEditorThemeFile = qsl("Mudlet.tmTheme");
}
pHost->mEditorThemeDark = attributes().value(QLatin1String("mEditorThemeDark")).toString();
pHost->mEditorThemeFileDark = attributes().value(QLatin1String("mEditorThemeFileDark")).toString();
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->mThemePreviewItemID = attributes().value(QLatin1String("mThemePreviewItemID")).toInt();
pHost->mThemePreviewType = attributes().value(QLatin1String("mThemePreviewType")).toString();
pHost->setHaveColorSpaceId(attributes().value(QLatin1String("mSGRCodeHasColSpaceId")).toString() == QLatin1String("yes"));
pHost->setMayRedefineColors(attributes().value(QLatin1String("mServerMayRedefineColors")).toString() == QLatin1String("yes"));
Redo fix cjk fullwidth character display (#1668) This is a squashed commit containing a number of changes: Something went wrong in trying to apply a Pull-Request from myself onto a PR Huadong Qi wanted to made to the Mudlet codebase which made it un-applyible. To solve this I have taken their original code, appended my extra code and which is merge into the main repository in a straightforward manner here. I have also, in this commit, filled out the copyright lines on the files that Huadong Qi modified and added the GPL template with their name onto the two new files that has been inserted into the code base. The main one wcwidth.cpp is a modified copy of Markus Knuth (C) 2007 wcwidth.c which bears the following licencing terms: "Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted. The author disclaims all warranties with regard to this software. Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c" As such this means that we can (need?) to re-license it under a GPL but it is my considered opinion that this is appropriate for our usage. Other notes from original commits: TTextEdit::drawLine: add non-BMP character support. Replace GetNextGraphemeSize with QTextBoundaryFinder Add option to control selection between wc_width()/wc_width_cjk() This is a quick-fix to accommodate the fact that some locales (not currently fully identified) require graphemes with the informative "East Asian Width" Unicode property of type "Ambiguous" to be drawn as narrow characters (the default case) and others (probably East Asian) as wide ones. The option is controlled (on a per profile basis) by a new checkbox on the Profile preference's "Main Display" tab - it is stored within the profile data so will persist between sessions. Leaving the profile preference control, now labelled: "Make 'Ambiguous' E. Asian width characters wide" in the tri-stated (partially-checked) default setting means that GBK and GB18030 MUD server encodings will use the 'wide' setting and all others the 'narrow' one, but allows the user to manually force the setting to be 'narrow' (unchecked) or 'wide' (checked) if required. NOTE: This commit finally puts the Q_OBJECT macro into play in the Host class - so it is important to ensure the qmake part of the build process is re-run after a build of a different branch of the code so that the moc correctly records that that class is one that it has to process. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2018-05-22 22:33:22 +01:00
if (attributes().hasAttribute("AmbigousWidthGlyphsToBeWide")) {
const QStringView ambiguousWidthSetting(attributes().value(qsl("AmbigousWidthGlyphsToBeWide")));
if (ambiguousWidthSetting == YES) {
pHost->setWideAmbiguousEAsianGlyphs(Qt::Checked);
} else if (ambiguousWidthSetting == qsl("auto")) {
pHost->setWideAmbiguousEAsianGlyphs(Qt::PartiallyChecked);
} else {
pHost->setWideAmbiguousEAsianGlyphs(Qt::Unchecked);
}
} else {
// The encoding setting is stored as part of the profile details and NOT
// in the save file - probably because it is needed before the
// connection to the Server is initiated so it will already be in place
// which is just as well as it is needed for the automatic case...
pHost->setWideAmbiguousEAsianGlyphs(Qt::PartiallyChecked);
Redo fix cjk fullwidth character display (#1668) This is a squashed commit containing a number of changes: Something went wrong in trying to apply a Pull-Request from myself onto a PR Huadong Qi wanted to made to the Mudlet codebase which made it un-applyible. To solve this I have taken their original code, appended my extra code and which is merge into the main repository in a straightforward manner here. I have also, in this commit, filled out the copyright lines on the files that Huadong Qi modified and added the GPL template with their name onto the two new files that has been inserted into the code base. The main one wcwidth.cpp is a modified copy of Markus Knuth (C) 2007 wcwidth.c which bears the following licencing terms: "Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted. The author disclaims all warranties with regard to this software. Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c" As such this means that we can (need?) to re-license it under a GPL but it is my considered opinion that this is appropriate for our usage. Other notes from original commits: TTextEdit::drawLine: add non-BMP character support. Replace GetNextGraphemeSize with QTextBoundaryFinder Add option to control selection between wc_width()/wc_width_cjk() This is a quick-fix to accommodate the fact that some locales (not currently fully identified) require graphemes with the informative "East Asian Width" Unicode property of type "Ambiguous" to be drawn as narrow characters (the default case) and others (probably East Asian) as wide ones. The option is controlled (on a per profile basis) by a new checkbox on the Profile preference's "Main Display" tab - it is stored within the profile data so will persist between sessions. Leaving the profile preference control, now labelled: "Make 'Ambiguous' E. Asian width characters wide" in the tri-stated (partially-checked) default setting means that GBK and GB18030 MUD server encodings will use the 'wide' setting and all others the 'narrow' one, but allows the user to manually force the setting to be 'narrow' (unchecked) or 'wide' (checked) if required. NOTE: This commit finally puts the Q_OBJECT macro into play in the Host class - so it is important to ensure the qmake part of the build process is re-run after a build of a different branch of the code so that the moc correctly records that that class is one that it has to process. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2018-05-22 22:33:22 +01:00
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->setEnableBlinkText(attributes().value(qsl("mEnableBlinkText")) == qsl("yes"));
Add: blinking/flashing text support (#8983) ## Summary Adds support for SGR codes 5 (slow blink) and 6 (rapid blink/flash) text attributes. ## Implementation Details ### Blink Timer Architecture - Global blink timer in `mudlet` singleton runs at 200ms interval (2.5 Hz, WCAG 2.3.1 compliant - under 3 Hz limit) - TTextEdit widgets register/unregister as blink clients - Timer only runs when at least one client needs it - Uses 4-state counter per ISO/IEC 8613-6:1994 to create two speeds: - **Slow blink (SGR 5)**: &lt; 150 cycles/min (~1.25 Hz) - **Fast blink (SGR 6)**: &gt; 150 cycles/min (~2.5 Hz) ### Text Attributes - New `TChar::AttributeFlags`: `Blink` and `FastBlink` - SGR 5 sets `Blink`, SGR 6 sets `FastBlink` - SGR 25 clears both flags ### Rendering - `TTextEdit::drawBackground()` skips drawing background for hidden blink text - `TTextEdit::drawForeground()` skips drawing foreground for hidden blink text - When blinking is disabled, blink text renders as italics instead ### User Preference - Per-profile `enableBlinkText` setting (disabled by default for accessibility) - Checkbox in Settings → Accessibility tab - Lua API: `getConfig("enableBlinkText")` / `setConfig("enableBlinkText", bool)` - Saved/loaded in profile XML ### Lua API - `getTextFormat()` reports blinking as `"none"`, `"slow"`, or `"fast"` - `setTextFormat()` accepts optional blink parameter: `"none"`, `"slow"`, or `"fast"` ## Testing To test blinking text, connect to a game that sends SGR 5/6 codes, or use: ```lua echo("\27[5mSlow blink\27[0m \27[6mFast blink\27[0m\n") ``` ## Checklist - [x] Blink timer starts/stops based on client registration - [x] Slow and fast blink speeds are visually distinct - [x] Preference toggles blinking on/off per profile - [x] Fallback to italics when blinking disabled - [x] WCAG 2.3.1 compliant (2.5 Hz, under 3 Hz limit) - [x] Default is disabled for accessibility considerations - [x] [`setTextFormat()`](https://wiki.mudlet.org/w/Area_51#setTextFormat.2C_PR_.238983) supports blink mode parameter --- https://github.com/user-attachments/assets/25f63605-7b90-40c3-963f-53889e41328d --------- Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2026-03-04 08:04:45 -05:00
if (attributes().hasAttribute("logFileNameFormat")) {
// We previously mixed "yyyy-MM-dd{#|T}hh-MM-ss" with "yyyy-MM-dd{#|T}HH-MM-ss"
// which is slightly different {always use 24-hour clock even if AM/PM is
// present (it isn't)} and that broke some code that requires an exact
// string to work with - now always change it to "HH":
pHost->mLogFileNameFormat = attributes().value(qsl("logFileNameFormat")).toString().replace(QLatin1String("hh"), QLatin1String("HH"), Qt::CaseSensitive);
pHost->mLogFileName = attributes().value(qsl("logFileName")).toString();
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
if (attributes().hasAttribute("mEditorShowBidi")) {
pHost->setEditorShowBidi(attributes().value(qsl("mEditorShowBidi")) == YES);
} else {
pHost->setEditorShowBidi(true);
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
if (attributes().hasAttribute("caretShortcut")) {
const QStringView caretShortcut(attributes().value(qsl("caretShortcut")));
if (caretShortcut == qsl("None")) {
pHost->mCaretShortcut = Host::CaretShortcut::None;
} else if (caretShortcut == qsl("Tab")) {
pHost->mCaretShortcut = Host::CaretShortcut::Tab;
} else if (caretShortcut == qsl("CtrlTab")) {
pHost->mCaretShortcut = Host::CaretShortcut::CtrlTab;
} else if (caretShortcut == qsl("F6")) {
pHost->mCaretShortcut = Host::CaretShortcut::F6;
}
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
if (attributes().hasAttribute("blankLineBehaviour")) {
const QStringView blankLineBehaviour(attributes().value(qsl("blankLineBehaviour")));
if (blankLineBehaviour == qsl("Hide")) {
pHost->mBlankLineBehaviour = Host::BlankLineBehaviour::Hide;
} else if (blankLineBehaviour == qsl("Show")) {
pHost->mBlankLineBehaviour = Host::BlankLineBehaviour::Show;
} else if (blankLineBehaviour == qsl("ReplaceWithSpace")) {
pHost->mBlankLineBehaviour = Host::BlankLineBehaviour::ReplaceWithSpace;
}
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
2018-05-08 12:27:07 +08:00
if (attributes().hasAttribute(QLatin1String("mSearchEngineName"))) {
pHost->mSearchEngineName = attributes().value(QLatin1String("mSearchEngineName")).toString();
2018-05-08 12:27:07 +08:00
} else {
pHost->mSearchEngineName = QString("Google");
}
if (attributes().hasAttribute(QLatin1String("mTimerSupressionInterval"))) {
pHost->mTimerDebugOutputSuppressionInterval = QTime::fromString(attributes().value(QLatin1String("mTimerSupressionInterval")).toString(), QLatin1String("hh:mm:ss.zzz"));
} else {
pHost->mTimerDebugOutputSuppressionInterval = QTime();
}
2019-07-25 15:22:14 +02:00
if (attributes().hasAttribute(QLatin1String("mDiscordAccessFlags"))) {
pHost->mDiscordAccessFlags = static_cast<Host::DiscordOptionFlags>(attributes().value(qsl("mDiscordAccessFlags")).toString().toInt());
2018-10-05 06:25:57 +02:00
}
improve: Give players full control over Discord Rich Presence (#9116) ## Summary Players had no clear way to control what Discord shows about their Mudlet activity. The old checkbox in the connection pane only gated server GMCP data but didn't prevent Discord from showing "Playing Mudlet", and the privacy controls were confusing. This PR replaces all of that with three straightforward modes via radio buttons in Profile Preferences > Chat: - **Show full game details (if supported)** - full game integration with server-provided presence (default) - **Show Mudlet only** - only shows "playing Mudlet", game server is not told about Discord - **Disabled** - Discord shows nothing about Mudlet Players pick the mode that matches their comfort level, and the existing privacy checkboxes (hide detail, hide state, etc.) remain available in Game details mode for finer control. ### What changed - **Three-mode radio buttons** in Profile Preferences > Chat with a two-column layout (modes on the left, privacy controls on the right), replacing the old connection-pane checkbox - **Server-origin tracking** so privacy checkboxes only gate data sent by the game server - Lua API calls always pass through (only Disabled mode blocks Lua entirely) - **Mid-session mode switching** via dynamic GMCP negotiation (Core.Supports.Add/Remove + External.Discord.Hello/Get) - **Deferred RPC init** - Discord RPC now starts when a profile loads, not on app launch - **Username restriction improvements** - takes effect immediately, case-insensitive (Discord usernames are lowercase-only since 2023), shuts down RPC when mismatched - **Shows logged-in Discord user** in preferences next to the restriction field, with a tooltip explaining the desktop app requirement when not connected - **Presence fix** - empty string fields now send nullptr so Discord hides them instead of showing blanks - **Memory leak fix** - presence allocations are now freed in the destructor regardless of RPC state ### Cleanup - Removed obsolete discriminator field (`mRequiredDiscordUserDiscriminator`) - Discord removed discriminators in 2023 - Removed dead code (`getDiscordUserDetails()`, never called) - Restored `Discord_ClearPresence` function pointer for potential future use - Use proper `Host::DiscordOptionFlags` types instead of raw `int` (thanks @SlySven) ### Known quirks - The "Hide timer" checkbox correctly omits timestamps from presence data, but Discord's client starts its own activity timer for any presence without a timestamp - this is Discord client behavior outside our control. - The "Hide large icon" setting clears the image key, but some Discord clients fall back to the application's default icon instead of hiding it entirely. ### Test plan - [ ] Open Profile Preferences > Chat tab - [ ] Switch between the three radio button modes and verify Discord presence updates accordingly - [ ] In Game details mode, toggle privacy checkboxes and verify fields are hidden/shown - [ ] Use Lua API (e.g. `setDiscordDetail("test")`) in Mudlet only mode - should work. Try in Disabled mode - should fail with error - [ ] Set a username restriction and verify presence clears immediately if mismatched - [ ] Run unit tests: `cd build && ./test/DiscordTest` - [ ] Run functional tests: `cd build && ctest -R TDiscordModeTest -V` Closes #6967. Supersedes #7438. --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: SlySven <slysven@virginmedia.com>
2026-04-08 13:33:09 +02:00
if (attributes().hasAttribute(QLatin1String("mDiscordMode"))) {
const int modeInt = attributes().value(qsl("mDiscordMode")).toString().toInt();
if (modeInt >= Host::DiscordDisabled && modeInt <= Host::DiscordShowGameDetails) {
pHost->mDiscordMode = static_cast<Host::DiscordMode>(modeInt);
}
}
if (attributes().hasAttribute(QLatin1String("mRequiredDiscordUserName"))) {
pHost->mRequiredDiscordUserName = attributes().value(QLatin1String("mRequiredDiscordUserName")).toString();
2018-10-05 06:25:57 +02:00
} else {
pHost->mRequiredDiscordUserName.clear();
}
Enhance: allow modification of the player room indication on 2D map (#2621) This is a squash-and-merge of a number of commits with the following edited summary: This PR reorganises the 2D Painter code to draw the player room indicator AFTER all the rooms have been drawn so that it does not get overdrawn by rooms painted after the player's room - which it could be if the rooms are at maximum size or the area is in "gridMode". It also offers some alternative marker options in the form of an oversized ring around the room which reduces the obstruction of the details of the room when the marker is drawn on it. The alternatives are: * a fixed red colour ring * a fixed blue/yellow colour ring - two contrasting colours mean that it can not be lost if drawn over a room that already has one of them as its colour (environment) setting. * a customizable two colour ring where the user can set the outer and inner colours as they like - even to the same colour. The ancient `(bool) Host::mMapStrongHighlight` option is still respected, I note that it was introduced in 3cb1719b0f516eae4fdbd9288e3f8e4e83e9ccbf from 2011/01/20 (after Mudlet 1.0.5) and the code to control it was lost in 8b0e8bb0f925d58c558cf864faae6b987435bd82 from 2012/12/31 "NEW Vadim Peretokin: mapper remembers settings" just before the release of Mudlet 2.0...! Refactor: ensure player room is drawn last This is done by extracting the relevant room drawing code to a separate inline function that is used whilst iterating through the area rooms to paint them, skipping but noting if the player room is found and then that function is used to paint the player's room afterwards. Revise: made code acceptable to all compilers The clang compiler does not like `auto` being used as a type in function prototypes as it is not formally part of the C++14 standard but a GCC extension - it got put in by the Qt Creator function extraction code option on the refactor menu. Revise: allow player room marking customisation to be saved and restored They are saved with the profile's data rather than the map. Revise: show transparency effects in custom player room marker colours It is not possible to just colour the background of the `QPushButton`s that set the custom colours to use for the *custom* player room marker as the transparency effects do not show. Instead this commit arranges for an icon with a black-and-white checker board pattern is over-painted with a brush in the relevant colour so that when the opacity is less than 100% the pattern is shown to an extent which is proportional to the degree of transparency of the colour chosen. Refactor: extract code to start 2D map speed-walk & simplify drawRoom code Suggested in peer review comment: https://github.com/Mudlet/Mudlet/pull/2621/#discussion_r298793485 Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-12-01 14:36:39 +00:00
if (attributes().hasAttribute(QLatin1String("playerRoomStyle"))) {
quint8 styleCode = 0;
quint8 outerDiameterPercentage = 0;
quint8 innerDiameterPercentage = 0;
QColor outerColor;
QColor innerColor;
// Retrieve current (possibly default) settings:
pHost->getPlayerRoomStyleDetails(styleCode, outerDiameterPercentage, innerDiameterPercentage, outerColor, innerColor);
// Gather values from file:
styleCode = static_cast<quint8>(qBound(0, attributes().value(QLatin1String("playerRoomStyle")).toInt(), 255));
outerDiameterPercentage = static_cast<quint8>(qBound(0, attributes().value(QLatin1String("playerRoomOuterDiameter")).toInt(), 255));
innerDiameterPercentage = static_cast<quint8>(qBound(0, attributes().value(QLatin1String("playerRoomInnerDiameter")).toInt(), 255));
Fix: correct warnings/errors found whilst working on Windows CI (#7224) #### Brief overview of PR changes/additions Whilst working on getting the Windows CI process to run in a MSYS2+Mingw-w64 environment on AppVeyor in both Qt 5 and 6 and both 32-bits and 64-bits (Qt6 only supports 64-Bit builds). I ran into a number of warnings, some of them about things deprecated in Qt 6.0 or later. This PR should eliminate all of them for our code (though there are a couple in upstream things). #### Motivation for adding to Mudlet Make the build process cleaner all around, especially with moving forward to Qt 6. #### Other info (issues closed, discussion etc) The use of `std::as_const(...)` requires C++17 but we have already mandated that. `qAsConst(...)` is deprecated in Qt 6. Some of the places where the above was being done also were missing the use of a `const` reference rather than the making of a constant copy of the iterated values; these have been fixed as well. A couple of Mudlet classes that I haven't yet cleaned up to move as much of the class initialisation to the header as possible were reporting initialisation ordering issue (`Host` and `TTimer`). I have fixed those but only in the region of the issues, more work there is desirable to clean up every remaining class - but I'm not allowed to leave "TODO:" comments around nowadays! :grinning: `(void) zip_error_to_str(char*, size_t, int, int))` has been obsoleted for a long time now, and I've finally put in something in a couple of places that will use the recommended replacement `(zip_error_t*) zip_get_error(zip*)` and dump the error message out to the OS console - which was not happening in the past. `(QString) QString::fromUtf16(...)` has been obsoleted and alternatives are suggested within the Qt documentation. I've used `QString::fromWCharArray(...)`. Whilst this compiles ***I am not 100% sure I have this correct and a second opinion on this change in `./src/mudlet.cpp` is desirable!*** Qt is renaming in Qt6 a few methods that otherwise function as before: * `(Qt::KeyboardModifiers) QDragEnterEvent::keyboardModifiers()` ==> `QDragEnterEvent::modifiers()` * `(Qt::KeyboardModifiers) QDragMoveEvent::keyboardModifiers()` ==> `QDragMoveEvent::modifiers()` * `(bool) QColor::isValidColor(const QString&)` ==> `(bool) QColor::isValidColorName(QAnyStringView)` * `(void) QColor::setNamedColor(const QString&)` ==> `(QColor) QColor::fromString(QAnyStringView)` * `(QString) QLocale::countryToString(Country)` ==> `(QString) QLocale::territoryToString(Territory)` Windows NTFS permissions checking was being done with a really low-level procedure which has been deprecated in Qt 6.6 and replaced with a slightly better (but also low-level) pair of functions: * `(bool) qEnableNtfsPermissionChecks()` * `(bool) qEnableNtfsPermissionChecks()` to do the same thing in almost the same way with a lesser risk of a "race-condition". There is a higher-level procedure involving the use of a new class `QNtfsPermissionCheckGuard` but that is a different way of doing things that is not a drop-in replacement AFAICT. There was an unhandled `case` (for `QTextToSpeech::State::Synthesizing`) in `(void) TLuaInterpreter::ttsStateChanged(QTextToSpeech::State)` - I've put in something to report that state but it is not clear that this, seemingly, transient state, needs anything extra than that. For instance, given that it looks to be associated with preparing a text to be spoken it might be reasonable to report the text involved as the `Speaking` state does... The point at which it was introduced is also unclear as that isn't documented! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2024-05-20 19:00:51 +00:00
outerColor = QColor::fromString(attributes().value(QLatin1String("playerRoomPrimaryColor")).toString());
innerColor = QColor::fromString(attributes().value(QLatin1String("playerRoomSecondaryColor")).toString());
Enhance: allow modification of the player room indication on 2D map (#2621) This is a squash-and-merge of a number of commits with the following edited summary: This PR reorganises the 2D Painter code to draw the player room indicator AFTER all the rooms have been drawn so that it does not get overdrawn by rooms painted after the player's room - which it could be if the rooms are at maximum size or the area is in "gridMode". It also offers some alternative marker options in the form of an oversized ring around the room which reduces the obstruction of the details of the room when the marker is drawn on it. The alternatives are: * a fixed red colour ring * a fixed blue/yellow colour ring - two contrasting colours mean that it can not be lost if drawn over a room that already has one of them as its colour (environment) setting. * a customizable two colour ring where the user can set the outer and inner colours as they like - even to the same colour. The ancient `(bool) Host::mMapStrongHighlight` option is still respected, I note that it was introduced in 3cb1719b0f516eae4fdbd9288e3f8e4e83e9ccbf from 2011/01/20 (after Mudlet 1.0.5) and the code to control it was lost in 8b0e8bb0f925d58c558cf864faae6b987435bd82 from 2012/12/31 "NEW Vadim Peretokin: mapper remembers settings" just before the release of Mudlet 2.0...! Refactor: ensure player room is drawn last This is done by extracting the relevant room drawing code to a separate inline function that is used whilst iterating through the area rooms to paint them, skipping but noting if the player room is found and then that function is used to paint the player's room afterwards. Revise: made code acceptable to all compilers The clang compiler does not like `auto` being used as a type in function prototypes as it is not formally part of the C++14 standard but a GCC extension - it got put in by the Qt Creator function extraction code option on the refactor menu. Revise: allow player room marking customisation to be saved and restored They are saved with the profile's data rather than the map. Revise: show transparency effects in custom player room marker colours It is not possible to just colour the background of the `QPushButton`s that set the custom colours to use for the *custom* player room marker as the transparency effects do not show. Instead this commit arranges for an icon with a black-and-white checker board pattern is over-painted with a brush in the relevant colour so that when the opacity is less than 100% the pattern is shown to an extent which is proportional to the degree of transparency of the colour chosen. Refactor: extract code to start 2D map speed-walk & simplify drawRoom code Suggested in peer review comment: https://github.com/Mudlet/Mudlet/pull/2621/#discussion_r298793485 Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-12-01 14:36:39 +00:00
// Store all the settings in the Host instance:
pHost->setPlayerRoomStyleDetails(styleCode, outerDiameterPercentage, innerDiameterPercentage, outerColor, innerColor);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
Enhance: allow modification of the player room indication on 2D map (#2621) This is a squash-and-merge of a number of commits with the following edited summary: This PR reorganises the 2D Painter code to draw the player room indicator AFTER all the rooms have been drawn so that it does not get overdrawn by rooms painted after the player's room - which it could be if the rooms are at maximum size or the area is in "gridMode". It also offers some alternative marker options in the form of an oversized ring around the room which reduces the obstruction of the details of the room when the marker is drawn on it. The alternatives are: * a fixed red colour ring * a fixed blue/yellow colour ring - two contrasting colours mean that it can not be lost if drawn over a room that already has one of them as its colour (environment) setting. * a customizable two colour ring where the user can set the outer and inner colours as they like - even to the same colour. The ancient `(bool) Host::mMapStrongHighlight` option is still respected, I note that it was introduced in 3cb1719b0f516eae4fdbd9288e3f8e4e83e9ccbf from 2011/01/20 (after Mudlet 1.0.5) and the code to control it was lost in 8b0e8bb0f925d58c558cf864faae6b987435bd82 from 2012/12/31 "NEW Vadim Peretokin: mapper remembers settings" just before the release of Mudlet 2.0...! Refactor: ensure player room is drawn last This is done by extracting the relevant room drawing code to a separate inline function that is used whilst iterating through the area rooms to paint them, skipping but noting if the player room is found and then that function is used to paint the player's room afterwards. Revise: made code acceptable to all compilers The clang compiler does not like `auto` being used as a type in function prototypes as it is not formally part of the C++14 standard but a GCC extension - it got put in by the Qt Creator function extraction code option on the refactor menu. Revise: allow player room marking customisation to be saved and restored They are saved with the profile's data rather than the map. Revise: show transparency effects in custom player room marker colours It is not possible to just colour the background of the `QPushButton`s that set the custom colours to use for the *custom* player room marker as the transparency effects do not show. Instead this commit arranges for an icon with a black-and-white checker board pattern is over-painted with a brush in the relevant colour so that when the opacity is less than 100% the pattern is shown to an extent which is proportional to the degree of transparency of the colour chosen. Refactor: extract code to start 2D map speed-walk & simplify drawRoom code Suggested in peer review comment: https://github.com/Mudlet/Mudlet/pull/2621/#discussion_r298793485 Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-12-01 14:36:39 +00:00
if (pHost->mpMap) {
// And the TMap instance:
pHost->mpMap->mPlayerRoomStyle = styleCode;
pHost->mpMap->mPlayerRoomOuterDiameterPercentage = outerDiameterPercentage;
pHost->mpMap->mPlayerRoomInnerDiameterPercentage = innerDiameterPercentage;
pHost->mpMap->mPlayerRoomOuterColor = outerColor;
pHost->mpMap->mPlayerRoomInnerColor = innerColor;
}
}
pHost->mRoomSize = attributes().value(qsl("mRoomSize")).toString().toDouble();
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (qFuzzyCompare(1.0 + pHost->mRoomSize, 1.0)) {
// The value is a float/double and the prior code using "== 0" is a BAD
// THING to do with non-integer number types!
2021-08-22 08:01:05 +02:00
pHost->mRoomSize = 0.5; // Same value as is in Host class initializer list
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->mLineSize = attributes().value(qsl("mLineSize")).toString().toDouble();
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (qFuzzyCompare(1.0 + pHost->mLineSize, 1.0)) {
2021-08-22 08:01:05 +02:00
pHost->mLineSize = 10.0; // Same value as is in Host class initializer list
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
add: separate border size control and player room marker improvements (#8975) #### Brief overview of PR changes/additions Closes #8857 This is a larger PR than I actually wanted it to be, but I could not make it all work, independently. Either it was one large PR, or several with dependencies to each other. I think this makes more sense as a single large one, as it's all related to the same settings window for the mapper. This is the window with all the changes: <img width="1116" height="1025" alt="Screenshot 2026-02-20 at 20 15 53" src="https://github.com/user-attachments/assets/b5a7aa04-5db2-434c-b1a2-9763a96e00ff" /> - Separate border size from exit line size with independent spinner controls, all rescaled to 1-11 range matching room size. The UI spinners use a simple reciprocal mapping (`mLineSize = 50 / spinner`) to convert the engine's inverse size representation into a "higher = thicker" scale <img width="613" height="74" alt="Screenshot 2026-02-20 at 20 08 21" src="https://github.com/user-attachments/assets/ffc6f141-38d2-457d-8e1e-35e042ad6be2" /> <img width="300" height="418" alt="Screenshot 2026-02-20 at 20 09 51" src="https://github.com/user-attachments/assets/a55b4aa4-7b83-48e7-82c4-de3cbcab490a" /> <img width="300" height="412" alt="Screenshot 2026-02-20 at 20 10 05" src="https://github.com/user-attachments/assets/8bdaccab-3e38-419f-ba4e-4c974856d66d" /> - Fix player room settings (style, colors) being lost when the mapper is opened after changing them, by syncing Host and TMap copies - Fix color swatch buttons showing stale icon alongside new color - Player room marker radius now accounts for room size, border width, and diagonal so 100% fully covers the room <img width="956" height="149" alt="Screenshot 2026-02-20 at 20 11 52" src="https://github.com/user-attachments/assets/0077c528-343a-46e1-afd5-4a3e3c31489b" /> - Add live-update connections for room borders, anti-alias, upper/lower levels, and symbol scaling factor - Extract gradient stop generation into a shared `T2DMap::buildPlayerRoomGradientStops()` static method used by both the map renderer and the preferences dialog - Cache invalidation for room size changes uses per-instance member variables instead of static locals, so multiple map views work correctly - Fix grid line width spinner having no visible effect - grid pen now scales with room dimensions like exits and borders, and includes the `setCosmetic()` call that all other map pens use #### Motivation for adding to Mudlet The exit size control also affected border width with no way to adjust them independently. The player room marker settings also had several persistence bugs where values would be lost when opening the mapper. #### Other info (issues closed, discussion etc) None **Test case:** 1. Open Profile Preferences > Mapper tab > Player room marker section 2. Change room size, exit size, and border size spinners independently - verify each affects only its respective element on the map 3. Change marker colors, switch to main Mudlet window, open the mapper, switch back to preferences and touch other controls - verify colors are not reset 4. If using multiple map views, verify each view's symbol/label caches invalidate independently when resized 5. Change the grid width spinner - verify grid line thickness changes visibly on the map at any zoom level --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Zooka <136661366+ZookaOnGit@users.noreply.github.com>
2026-03-27 15:57:55 +01:00
pHost->mRoomBorderSize = attributes().value(qsl("mRoomBorderSize")).toString().toDouble();
if (qFuzzyCompare(1.0 + pHost->mRoomBorderSize, 1.0)) {
// For old profiles without border size, use mLineSize to preserve
// the previous behavior where border and exit shared the same size
pHost->mRoomBorderSize = pHost->mLineSize;
}
pHost->mMapGridLineSize = attributes().value(qsl("mMapGridLineSize")).toString().toDouble();
if (qFuzzyCompare(1.0 + pHost->mMapGridLineSize, 1.0)) {
pHost->mMapGridLineSize = 0.5; // Same value as is in Host class initializer list
}
const QStringView ignore(attributes().value(qsl("mDoubleClickIgnore")));
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
for (auto character : ignore) {
pHost->mDoubleClickIgnore.insert(character);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
if (attributes().hasAttribute(QLatin1String("EditorSearchOptions"))) {
pHost->setSearchOptions(static_cast<dlgTriggerEditor::SearchOptions>(attributes().value(qsl("EditorSearchOptions")).toInt()));
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->setDebugShowAllProblemCodepoints(attributes().value(qsl("DebugShowAllProblemCodepoints")) == YES);
2019-07-25 15:22:14 +02:00
const bool compactInputLine = attributes().value(QLatin1String("CompactInputLine")) == YES;
pHost->setCompactInputLine(compactInputLine);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
if (mudlet::self()->mpCurrentActiveHost == pHost) {
mudlet::self()->dactionInputLine->setChecked(compactInputLine);
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
Add persistent command history (#6767) #### Brief overview of PR changes/additions Saves each command line's history when a profile is closed and restores the data the next time the profile is opened. Each command line is handled separately. #### Motivation for adding to Mudlet It is a bounty item! #### Other info (issues closed, discussion etc) This works for command lines of all types, and saves them all separately in the profile's base directory. This should close https://github.com/Mudlet/Mudlet/issues/2007. We'll avoid using the names for the extra command lines as part of a filename by instead storing them in a `QSettings` per profile `profile.ini` format file. Using such a file to store per-profile details is something that has been on my TODO list for years (I prototyped code to do it at least as far back as 2016 I think) - so I have added two functions to the Host class that hopefully can eventually replace the existing `readProfileData(...)` and `writeProfileData(...)`. Also added code to fix a corner case where a TCommandLine has a name containing '/' or '\'. Also added a limit to the number of command line history entries to save. Otherwise it will grow indefinitely large as every single entry is retained. A knob for this has been provided on the profile preferences and it is saved with the profile's XML game save file (not in the base directory of the profile). It covers the range of 0 to 10,000 entries with a default of 500 and a logarithmic step size (1, 2, 5, 10) for each multiple of 10. This value is applied to ALL command lines in a profile. Note that this limit is only applied when the commend history is saved, it can still grow to be larger than the limit whilst the profile is active! A pair of lua API functions are added: * `setSaveCommandHistory([commandLineName,] save)` to enable (`true`) or disable (`false`) the main, or if specified, any other command-line * `getSaveCommandHistory([commandLineName])` returns two values first a boolean indicating whether the main, or if specified, any other command-line will save its history (to a specified number set separately) or not, between sessions and secondly a text message which either reports that the history will be saved and how many entries or that it will not and the reason why. Also the `setConfig(...)`/`getConfig(...)` general settings functions gain a new option `commandLineHistorySaveSize` which sets the number of most recent commands stored for ALL command-lines in the given profile for which saving is enabled . The setter accepts a number of values - which are duplicates of the values available on a new "knob" in the Profile Preferences and the getter will report which of those has been set. Setting the 'none' or '0' option will disable saving for ALL command-lines so that they behave as they would before this feature is introduced. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2023-05-31 01:54:20 +01:00
if (attributes().hasAttribute(QLatin1String("CommandLineHistorySaveSize"))) {
pHost->setCommandLineHistorySaveSize(attributes().value(QLatin1String("CommandLineHistorySaveSize")).toInt());
} else {
// This is the default value, though prior to the introduction of this
// it would have effectively been zero:
pHost->setCommandLineHistorySaveSize(500);
}
Enhance: allow wait for more network packets to be adjusted (#5403) This might be useful for tweaking for MUDs that do not use Go Aheads for end-users with a good network connection. In #5415 which was a (presumably accidental) duplicate of this PR @vadi2 suggested the following as a replacement for the tool-tip for the option: "Go-Ahead (GA) tells Mudlet when the game server is done sending text. On games that don't support GA, this option controls how long Mudlet will wait for more text to arrive. Larger values will help reduce the risk that a large piece of text has unintended linebreaks in the middle of it, which would break triggers. Lesser values will increase the risk of text getting broken up, but will make the game feel more responsive." in case it is not clear from the commit I have revised the text to partial include some of that - and also taken on board Leris/Kebap who pointed out on Discord that GA is not the only means of the Server signalling that it has finished sending out packets. The text is now along the lines of (within Markup limitations): "*Go-Ahead* (`GA`) / *End-of-record* (`EOR`) signalling are Telnet enhancements that tell Mudlet when the Game Server is done sending a piece of text. On Game Servers which do not provide `GA` or `EOR` this option controls how long Mudlet will wait for further network packets (i.e. text or other 'out-of-band' `OOB` data) to arrive. The default is 300 milli-seconds. Larger values will help to prevent unintended linebreaks in the middle of big pieces of text which may break triggers; smaller values may make Mudlet seem more responsive to incoming text but runs a risk of breaking up text (or more problematically `OOB` data). *Adjustment of this persistent per-profile control is **NOT** recommended unless you understand what it is doing and why it might be helpful. Fine-tuning is likely to depend on particular network conditions and MUD Game servers and a lower (shorter wait) setting that works for one user may not be long enough for others.*" He also suggested replacing the option as it is called "Network packet timeout:" on the basis that: "This text is great for an engineer who knows the context, but not so much for a player who doesn't. How about: 'Wait up to [ ]ms for more text to arrive?'" however I felt that was too wordy and could get broken in translation to other locales. Also - given the potential for breakage, particularly if it is set too small - we do not want the player who does not get it, to play around with it. Note that although I now mention something to the effect that the setting is per profile and is saved between sessions that has not been coded yet. It will follow in an additional commit that is pending. Revised the tool-tip text AGAIN and move the display of the unit (mSec) to the label from the spin-box - to make translation a tiny bit simpler. Also: * To allow for the control to display the time in seconds it has to be converted from a `QSpinBox` to a `QDoubleSpinBox` and some properties tweaked to match - beyond the control the C++ code still uses an integer representing the time out in milliseconds. * Reorder the tab order for a couple of other controls that have been added since it was last redone - otherwise tabbing across them will cause odd jumps between different pages of the profile preferences dialogue. * Remove a redundant default text for a label that "lights up" when profile passwords are being migrated between secure and portable storage modes - the text should never shown to the end-user - but just in case it does a slightly more informative message than the default translatable "TextLabel" will be used. Revised the display of the unit from "mSec" to "seconds"in the spin-box Signed-off by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
2021-09-26 17:01:34 +01:00
if (attributes().hasAttribute(QLatin1String("NetworkPacketTimeout"))) {
// These limits are also hard coded into the QSpinBox used to adjust
// this setting in the preferences:
pHost->mTelnet.setPostingTimeout(qBound(10, attributes().value(QLatin1String("NetworkPacketTimeout")).toInt(), 500));
} else {
// The default value, also used up to Mudlet 4.12.0:
pHost->mTelnet.setPostingTimeout(300);
}
if (attributes().hasAttribute(QLatin1String("ControlCharacterHandling"))) {
switch (attributes().value(QLatin1String("ControlCharacterHandling")).toInt()) {
case 1:
pHost->setControlCharacterMode(ControlCharacterMode::Picture);
break;
case 2:
pHost->setControlCharacterMode(ControlCharacterMode::OEM);
break;
case 0:
[[fallthrough]];
default:
pHost->setControlCharacterMode(ControlCharacterMode::AsIs);
}
} else {
// The default value, also used up to Mudlet 4.14.1:
pHost->setControlCharacterMode(ControlCharacterMode::AsIs);
}
if (attributes().hasAttribute(qsl("ShowIDsInEditor"))) {
pHost->setShowIdsInEditor(attributes().value(qsl("ShowIDsInEditor")) == YES);
} else {
// The default (and for profile files from before 4.18.0):
pHost->setShowIdsInEditor(false);
}
if (attributes().hasAttribute(qsl("Large2DMapAreaExitArrows"))) {
pHost->setLargeAreaExitArrows(attributes().value(qsl("Large2DMapAreaExitArrows")) == YES);
} else {
// The default (and for map/profile files from before 4.15.0):
pHost->setLargeAreaExitArrows(false);
}
QMargins borders;
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
// Only read this detail into a backup location so that it can
// be imported without changing the main setting unless it is
// needed (intended for use when importing a profile but not
// otherwise). In fact this detail is normally stored outside of
// the game save in the profile base directory:
pHost->mBackupHostName = readElementText();
} else if (name() == qsl("mInstalledModules")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
QMap<QString, QStringList> entry;
readModulesDetailsMap(entry);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
QMapIterator<QString, QStringList> it(entry);
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (it.hasNext()) {
it.next();
QStringList moduleList;
const QStringList entryList = it.value();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
moduleList << entryList.at(0);
moduleList << entryList.at(1);
pHost->mInstalledModules[it.key()] = moduleList;
pHost->mModulePriorities[it.key()] = entryList.at(2).toInt();
Add: streamlined module creation feature (#8039) # Fix: Add streamlined module creation feature ## Overview Implements a direct "Create Module" workflow in the trigger editor, eliminating the clunky export-then-import process described in issue #566. ## Changes Made ### Files Modified: - **dlgTriggerEditor.h** - Added new action and slot declarations - **dlgTriggerEditor.cpp** - Implemented "Create Module" button and functionality - **dlgPackageExporter.h** - Added preselection and module creation mode methods - **dlgPackageExporter.cpp** - Enhanced to support module creation workflow ### Key Features: 1. **New "Create Module" button** in trigger editor toolbar (📦 icon) 2. **Context-aware preselection** - automatically selects current item 3. **Module creation mode** - configures package exporter for module workflow 4. **Auto-installation** - modules are installed immediately after creation 5. **Streamlined UX** - single-click process from selection to installed module ## Implementation Details ### dlgTriggerEditor Changes: - Added `mpCreateModuleAction` toolbar button with package-exporter icon - Implemented `slot_createModule()` that opens package exporter in module mode - Pre-selects current item based on editor view type (Trigger/Alias/Script/etc.) ### dlgPackageExporter Enhancements: - Added `setModuleCreationMode()` to configure UI for module creation - Added preselect methods for all item types (Trigger, Timer, Alias, Script, Action, Key) - Modified export completion to auto-install as module when in module creation mode - Updated window title and prompts for module creation workflow ## Related Issues Closes #566 /claim #566 ## Screenshots *Note: Screenshots can be added showing the new Create Module button in the trigger editor toolbar and the enhanced package exporter dialog in module creation mode.* <img width="1920" height="1200" alt="Screenshot from 2025-08-16 20-05-59" src="https://github.com/user-attachments/assets/560a3e29-1a91-4a58-a930-94474701d861" /> https://github.com/user-attachments/assets/dbaa7019-c853-4d33-86be-5c39dd4c1fa4 <img width="1920" height="1200" alt="image" src="https://github.com/user-attachments/assets/631e202c-7d05-4ba9-8c03-7d33e90d7dfd" /> --------- Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2025-08-21 09:58:38 +05:30
// Also add to active modules list to match runtime state
if (!pHost->mActiveModules.contains(it.key())) {
pHost->mActiveModules.append(it.key());
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
} else if (name() == qsl("mInstalledPackages")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readStringList(pHost->mInstalledPackages, qsl("Host"));
} else if (name() == qsl("url")) {
// Only read this detail into a backup location so that it can
// be imported without changing the main setting unless it is
// needed (intended for use when importing a profile but not
// otherwise). In fact this detail is normally stored outside of
// the game save in the profile base directory:
pHost->mBackupUrl = readElementText();
} else if (name() == qsl("serverPackageName")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pHost->mServerGUI_Package_name = readElementText();
} else if (name() == qsl("serverPackageVersion")) {
pHost->mServerGUI_Package_version = readElementText();
} else if (name() == qsl("port")) {
// Only read this detail into a backup location so that it can
// be imported without changing the main setting unless it is
// needed (intended for use when importing a profile but not
// otherwise). In fact this detail is normally stored outside of
// the game save in the profile base directory:
pHost->mBackupPort = readElementText().toInt();
} else if (readHostBorderElement(borders, name())) {
// Handled by helper
} else if (name() == qsl("commandLineMinimumHeight")) {
pHost->commandLineMinimumHeight = readElementText().toInt();
} else if (name() == qsl("wrapAt")) {
// toInt() yields 0 for anything unparseable, and a profile that
// wraps at zero columns can show no text at all
pHost->mWrapAt = qMax(1, readElementText().toInt());
} else if (name() == qsl("wrapIndentCount")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pHost->mWrapIndentCount = readElementText().toInt();
} else if (name() == qsl("wrapHangingIndentCount")) {
pHost->mWrapHangingIndentCount = readElementText().toInt();
} else if (name() == qsl("undoServerWrapWidth")) {
pHost->mUndoServerWrapWidth = qBound(20, readElementText().toInt(), 500);
} else if (name() == qsl("consoleBufferSize")) {
pHost->mConsoleBufferSize = readElementText().toInt();
} else if (name() == qsl("useMaxConsoleBufferSize")) {
pHost->mUseMaxConsoleBufferSize = (readElementText() == qsl("yes"));
} else if (name() == qsl("mCommandSeparator")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pHost->mCommandSeparator = readElementText();
} else if (readHostColorElement(pHost, name())) {
// Handled by helper
} else if (name() == qsl("mDisplayFont")) {
2019-08-23 07:30:54 +02:00
pHost->setDisplayFontFromString(readElementText());
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
#if QT_VERSION < QT_VERSION_CHECK(6, 9, 0)
// On GNU/Linux and FreeBSD ensure that emojis are displayed in
// colour even if this font doesn't support it:
Infrastructure: rationalise font handling (#7918) #### Brief overview of PR changes/additions * Revert redesign of main font selection in preferences. * Restructure usage of fonts to remove the somewhat redundent `(QFont) mDisplayFont` for widgets that inherently have their own (QFont) which they use for painting operations. * Provide a means to track only the details of `QFont`s that we care about which should be more lightweight than holding a complete copy of a font (in `TFontDetails`). * Include the "antialisaing" detall for the main display font (only for the main console) in the active updates that changing the main font in the preferences produces. * Apply changes to the font in a `TConsole` to **all** the `TCommandLine`s associated with it. #### Brief overview of PR changes/additions * The previously revised font settings in the preferences that used a native font selection was not as useful as it seemed - at least the Windows one offered controls that we did not need or use which meant they had not actual effects which would be confusing to the end user. * Storing a separate copy of `QFont`s did not seem productive especially as it was easy to modify the intrinsic one and not the copy or vice-versa. * Adding a separate class to track the font details we ARE interested in makes it easier to compare fonts and to tell whether two instances are the same as far as Mudlet is concerned * It was not clear that the "anti-aliasing" setting was being correctly applied/used where it was intended - with this PR it is also updated as it is changed in the prefernces along with the other two settings: font "family" and "size". * The font in command-lines now clearly follow the main console or a sub- console that they belong to. #### Other info (issues closed, discussion etc) Once this is done it is perhaps a bit clearer that the Lua API `setFont(["windowName", ] "fontName")` sets the font family to use for the main or (if given a name) a sub-console/user-window - and if it is the "Main console" that also carries through into: * the Lua script window in the editor * the error window in the editor * the "notepad" * the map info display in the 2D mapper the font is also replicated in the corresponding "command-lines" for that "console". The Lua API `setFontSize(["windowName", ]integer)` sets the font size for all the places where the correspond font had been set by the `setFont(...)` call. Setting the font name and size via the Lua API are two separate operations and they do act seemingly independently of each other. Setting these things via the preferences take effect on the main console (and related things) immediately (except for the mapper - that only updates when the preferences dialogue is closed) - the anti-alias setting also acts on these things in the same manner (which it didn't before IIRC). As a side effect of the reversion this will close #7907! I have a separate commit that gives the option for sub-console/user-windows to track the main console font family (so that changing the font in there carries through into those other windows) - optionally they can *also* track the size of the main font (by a user/scriptable factor) so that as the main font is made smaller or larger so do the other consoles - however this can be switched off if not wanted. I've let that as a separate commit because it would just enlarge this already meaty PR and it can be safely left to be reviewed/done separately! --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2025-07-06 16:47:25 +01:00
QFont::insertSubstitution(pHost->getDisplayFont().family(), qsl("Noto Color Emoji"));
#endif
// For Qt 6.9+, emoji font support is handled globally in FontManager::addEmojiFont()
#endif
} else if (name() == qsl("mCommandLineFont")) {
Infrastructure: rationalise font handling (#7918) #### Brief overview of PR changes/additions * Revert redesign of main font selection in preferences. * Restructure usage of fonts to remove the somewhat redundent `(QFont) mDisplayFont` for widgets that inherently have their own (QFont) which they use for painting operations. * Provide a means to track only the details of `QFont`s that we care about which should be more lightweight than holding a complete copy of a font (in `TFontDetails`). * Include the "antialisaing" detall for the main display font (only for the main console) in the active updates that changing the main font in the preferences produces. * Apply changes to the font in a `TConsole` to **all** the `TCommandLine`s associated with it. #### Brief overview of PR changes/additions * The previously revised font settings in the preferences that used a native font selection was not as useful as it seemed - at least the Windows one offered controls that we did not need or use which meant they had not actual effects which would be confusing to the end user. * Storing a separate copy of `QFont`s did not seem productive especially as it was easy to modify the intrinsic one and not the copy or vice-versa. * Adding a separate class to track the font details we ARE interested in makes it easier to compare fonts and to tell whether two instances are the same as far as Mudlet is concerned * It was not clear that the "anti-aliasing" setting was being correctly applied/used where it was intended - with this PR it is also updated as it is changed in the prefernces along with the other two settings: font "family" and "size". * The font in command-lines now clearly follow the main console or a sub- console that they belong to. #### Other info (issues closed, discussion etc) Once this is done it is perhaps a bit clearer that the Lua API `setFont(["windowName", ] "fontName")` sets the font family to use for the main or (if given a name) a sub-console/user-window - and if it is the "Main console" that also carries through into: * the Lua script window in the editor * the error window in the editor * the "notepad" * the map info display in the 2D mapper the font is also replicated in the corresponding "command-lines" for that "console". The Lua API `setFontSize(["windowName", ]integer)` sets the font size for all the places where the correspond font had been set by the `setFont(...)` call. Setting the font name and size via the Lua API are two separate operations and they do act seemingly independently of each other. Setting these things via the preferences take effect on the main console (and related things) immediately (except for the mapper - that only updates when the preferences dialogue is closed) - the anti-alias setting also acts on these things in the same manner (which it didn't before IIRC). As a side effect of the reversion this will close #7907! I have a separate commit that gives the option for sub-console/user-windows to track the main console font family (so that changing the font in there carries through into those other windows) - optionally they can *also* track the size of the main font (by a user/scriptable factor) so that as the main font is made smaller or larger so do the other consoles - however this can be switched off if not wanted. I've let that as a separate commit because it would just enlarge this already meaty PR and it can be safely left to be reviewed/done separately! --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2025-07-06 16:47:25 +01:00
// We use the same font as the main console now so discard this
// one silently:
Q_UNUSED(readElementText())
} else if (name() == qsl("commandSeperator")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
// Ignore this misspelled duplicate, it has been removed from
// the Xml format but will appear in older files and trip the
// QDebug() error reporting associated with the following
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
// readUnknownElement(...) for "anything not otherwise parsed"
Q_UNUSED(readElementText())
} else if (name() == qsl("mSpellDic")) {
Enhance: add per profile dictionary capability (#2358) This is a squash and merge PR and the following is an edited summary of the individual commit messages that were combined into it: It is saved at the end of a session and the affix file ('profile.aff') is maintained to allow for the Hunspell suggestion capability to operate. The word-list ('profile.dic') file is checked at session start to accommodate manual editing (adding/removing words) between sessions. When a word typed on the command line is not found in the main (system provided on non-Windows OSes) instead of the red (now wavy on Unix, dotted on macOS) underline a cyan dashed underline is used to show that the word was found in the profile's own dictionary. Words can also be added and removed. Also found out why the wavy / dashed underline was not showing in previous/ initial attempt. Some lua commands are also added: * addWordToDictionary((string) word) returns true if the word was added (and was not already in the dictionary) * removeWordFromDictionary((string) word) returns true if the word was present and removed from the dictionary. * getDictionaryWordList()` returns a (sorted into system locale case insensitive order) list of ALL words in the profile dictionary. * `getDictionaryWordList((string) word [,(bool)useProfileDictionary])` do a check in the specified system dictionary (default) or if a second argument is supplied and is `true` use the per profile one. Returns `true` if the word is found present in the dictionary, and false if not. * spellCheckWord((string) word) [,(bool)useUserDictionary]) returns true if the word is in the dictionary - uses the main language dictionary as set in the profile preferences unless a second, optional boolean true argument is provided then it will use the user's stored word list - either the per profile or the shared across profiles as set in the profile preferences. * spellSuggestWord((string) word [,(bool)useUserDictionary]) does the same sort of suggestions search as is done on the console command line and returns a list of suggestions from the specified system dictionary (default) or if a second argument is supplied and is `true` then it will use the user's stored word list - either the per profile or the shared across profiles as set in the profile preferences. Also: * Arrange to not list supplemental medical dictionaries. * Improve system dictionary selection by added text for all the dictionaries I can identify in my Linux system distribution. * Reordered some items in the mudlet constructor initialisation list to match their placement in the header file - it was helpful to do this as I found I needed to add an initialiser for a pointer and wanted to put it in the right place. * Revise: add more Hunspell dictionary details found on FreeBSD Also switch to consider the `.aff` files in case there are additional or supplemental `.dic` files. Some dictionaries were also found which used a '-' as a separator, particularly where the language code had a third element. Officially the language codes should have a lower case first part (language), an upper case second part (country or large scale classification) and if there is a third part it should be in "Title" case. To enable quick look-up the QMap is populated with all lowercase keys and with all '-' converted to '_'. Fix things so that the selected dictionary is in view when the preferences dialogue is created. Do not bother to check the return values from Hunspell_add and Hunspell_remove - they do not seem to be useful. Improve the dictionary location code to work for using bundled dictionaries when building in a shadow directory. (I found this whilst building in my slightly non-standard Windows build environment). Refactor: * mudlet::prepareProfileDictionary(...) * mudlet::prepareSharedDictionary() * mudlet::saveDictionary(...) so that they use a number of common subroutines. Change the lua getDictionaryWordList so that its output is sorted in a case-insensitive manner instead of a case-sensitive manner. Also handle the case should a main dictionary not be found. Revise: after peer review disable the option to NOT use a user dictionary As there is some careful coding in the existing code to prevent unnecessary loading and unloading of the per profile and shared user dictionaries it is easier to just prevent the option to disable both of them from being chosen - at least whilst evaluating things - this will maintain the presence of the "mEnableUserDictionary = 'yes'" option in new profile saves. Revise: recheck word after dict. options changes & clear marks when off As requested during peer review - this in fact improves upon situation before the start of adding user dictionaries. Revise: recheck word after adding/removing it from user's dictionary It is better now at changing the indication between unknown and in the user's dictionary for a word that is not in the main one - but it is not perfect, especially if there are additional punctuation marks abutting the word concerned. Also added indication of which of the per profile or the shared user dictionaries is providing the user dictionary suggestions. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-03-08 09:28:55 +01:00
pHost->setSpellDic(readElementText());
} else if (name() == qsl("mLineSize") || name() == qsl("mRoomSize")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
// These two have been dropped from the Xml format as these are
// duplicates of attributes that were being incorrected read in
// the parent <Host ...> element as integers {they are stored as
// decimals but for the first one at least, it is a decimal
// number n, where 0.1 <= n <= 1.1 so was being read as "0" for
// all but the greatest 2 values where it was read as "1"!}
// We still check for them so that we avoid falling into the
// QDebug() error reporting associated with the following
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
// readUnknownElement(...) for "anything not otherwise parsed"
Q_UNUSED(readElementText())
} else if (name() == qsl("mMapInfoContributors")) {
readLegacyMapInfoContributors();
} else if (name() == qsl("mapInfoContributor")) {
readMapInfoContributor();
} else if (name() == qsl("profileShortcut")) {
readProfileShortcut();
} else if (name() == qsl("stopwatches")) {
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
readStopWatchMap();
} else if (name() == qsl("MMCP")) {
readMMCPOptions();
Improve: add a new, experimental 3D mapper (#8087) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions This adds an experimental, new 3D mapper that uses shaders, more modern openGL, and a far better code reorganization that makes it an easier foundation to build upon. The new 3D mapper is here side by side with the original and can be toggled on for experimentation. There's a lot of work to be done, so I'd rather merge it early instead of making a mega-PR. #### Motivation for adding to Mudlet So we have a new foundation to build upon and improve. #### Other info (issues closed, discussion etc) Old and new mapper can be toggled dynamically with: ```lua -- this can be a keybinding setConfig("experiment.3dmap.modernmapper", not getConfig("experiment.3dmap.modernmapper")) ``` Smooth movement is one experiment in the new mapper, and it can be enabled with: ```lua lua setConfig("experiment.rendering.smooth-camera", true) ``` As you notice an experiments system has been added so we can implement things at once and experiment to choose the one that works best. This system can be used in other places in Mudlet as well. <details><summary>Details</summary> <p> ## Experiments System ### Overview Allows enabling/disabling experimental features via `setConfig`/`getConfig` with validation against a predefined whitelist. ### Usage ```lua -- Enable experiment setConfig("experiment.rendering.more-transparent", true) -- Check if enabled local enabled = getConfig("experiment.rendering.more-transparent") -- returns true/false -- Get active experiment in group local active = getConfig("experiment.rendering.active") -- returns "more-transparent" -- List all valid experiments local experiments = getConfig("experiment.list") -- returns table of valid keys ``` ### Behavior - Grouped experiments: Mutually exclusive (enabling one disables others in same group) - Validation: Only predefined experiments allowed, invalid keys return errors - Persistence: Experiment states saved/loaded with profiles ### Adding New Experiments Edit Host::mValidExperiments in src/Host.cpp: ```cpp const QSet<QString> Host::mValidExperiments = { qsl("experiment.rendering.originalish"), qsl("experiment.rendering.more-transparent"), qsl("experiment.newfeature.option1"), // Add here }; ``` ### Current Experiments - experiment.rendering.originalish - experiment.rendering.more-transparent </p> </details> --------- Co-authored-by: Vadim Peretokin <vadi2@users.noreply.github.com>
2025-08-29 12:15:48 +02:00
} else if (name() == qsl("experiment")) {
QString key = attributes().value(qsl("key")).toString();
bool enabled = attributes().value(qsl("enabled")) == YES;
if (enabled && !key.isEmpty()) {
mpHost->setExperimentEnabled(key, true);
}
readElementText(); // consume the element
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("Host"));
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
}
}
Improve: Support Mud Terminal Type Standard (MTTS) (#7036) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Implemented [Mud Terminal Type Standard](https://tintin.mudhalla.net/protocols/mtts/) (MTTS): * Added "Advertise screen reader use to games supporting MTTS" to the Accessibility menu * Added "Force MTTS Negotiation Off" to the Special Options menu * Negotiate MTTS when prompted by the server, telling servers that * Client supports all common ANSI color codes. * Client supports all common VT100 codes (we don't, I think?). * Client is using UTF-8 character encoding. * Client supports all 256 color codes. * Client supports xterm mouse tracking (we don't, I think?). * Client supports the OSC color palette. * Client is using a screen reader (opt-in required, not advertised by default) * Client is a proxy allowing different users to connect from the same IP address * Client supports truecolor codes using semicolon notation. * Client supports the Mud New Environment Standard for information exchange (we don't, yet). * Client supports the Mud Server Link Protocol for clickable link handling (we don't, yet). * Client supports SSL for data encryption, preferably TLS 1.3 or higher. #### Motivation for adding to Mudlet Advertise that Mudlet supports many of the above items (particularly UTF-8, TRUECOLOR, Screen Reader) #### Other info (issues closed, discussion etc) Closes #1208 Out of scope: Initiating another negotiation if supported standards change during session --------- Co-authored-by: Michael Conley <mconley@michaels-mbp.lan> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-12-24 06:13:19 -05:00
pHost->setUserBorders(borders);
pHost->loadPackageInfo();
}
2019-01-06 06:29:16 -05:00
bool XMLimport::readHostColorElement(Host* pHost, QStringView elementName)
{
// Simple colors (no alpha channel)
static const QHash<QString, QColor Host::*> simpleColors = {
{qsl("mCommandLineFgColor"), &Host::mCommandLineFgColor},
{qsl("mCommandLineBgColor"), &Host::mCommandLineBgColor},
{qsl("mFgColor"), &Host::mFgColor},
{qsl("mCommandFgColor"), &Host::mCommandFgColor},
{qsl("mCommandBgColor"), &Host::mCommandBgColor},
{qsl("mBlack"), &Host::mBlack},
{qsl("mLightBlack"), &Host::mLightBlack},
{qsl("mRed"), &Host::mRed},
{qsl("mLightRed"), &Host::mLightRed},
{qsl("mBlue"), &Host::mBlue},
{qsl("mLightBlue"), &Host::mLightBlue},
{qsl("mGreen"), &Host::mGreen},
{qsl("mLightGreen"), &Host::mLightGreen},
{qsl("mYellow"), &Host::mYellow},
{qsl("mLightYellow"), &Host::mLightYellow},
{qsl("mCyan"), &Host::mCyan},
{qsl("mLightCyan"), &Host::mLightCyan},
{qsl("mMagenta"), &Host::mMagenta},
{qsl("mLightMagenta"), &Host::mLightMagenta},
{qsl("mWhite"), &Host::mWhite},
{qsl("mLightWhite"), &Host::mLightWhite},
{qsl("mFgColor2"), &Host::mFgColor_2},
{qsl("mLowerLevelColor"), &Host::mLowerLevelColor},
{qsl("mUpperLevelColor"), &Host::mUpperLevelColor},
{qsl("mRoomBorderColor"), &Host::mRoomBorderColor},
{qsl("mRoomCollisionBorderColor"), &Host::mRoomCollisionBorderColor},
{qsl("mBlack2"), &Host::mBlack_2},
{qsl("mLightBlack2"), &Host::mLightBlack_2},
{qsl("mRed2"), &Host::mRed_2},
{qsl("mLightRed2"), &Host::mLightRed_2},
{qsl("mBlue2"), &Host::mBlue_2},
{qsl("mLightBlue2"), &Host::mLightBlue_2},
{qsl("mGreen2"), &Host::mGreen_2},
{qsl("mLightGreen2"), &Host::mLightGreen_2},
{qsl("mYellow2"), &Host::mYellow_2},
{qsl("mLightYellow2"), &Host::mLightYellow_2},
{qsl("mCyan2"), &Host::mCyan_2},
{qsl("mLightCyan2"), &Host::mLightCyan_2},
{qsl("mMagenta2"), &Host::mMagenta_2},
{qsl("mLightMagenta2"), &Host::mLightMagenta_2},
{qsl("mWhite2"), &Host::mWhite_2},
{qsl("mLightWhite2"), &Host::mLightWhite_2},
};
// Colors that support alpha channel
static const QHash<QString, QColor Host::*> alphaColors = {
{qsl("mBgColor"), &Host::mBgColor},
{qsl("mBgColor2"), &Host::mBgColor_2},
{qsl("mMapGridColor"), &Host::mMapGridColor},
{qsl("mMapInfoBg"), &Host::mMapInfoBg},
};
const QString elemName = elementName.toString();
if (auto it = simpleColors.find(elemName); it != simpleColors.end()) {
pHost->*it.value() = QColor::fromString(readElementText());
return true;
}
if (auto it = alphaColors.find(elemName); it != alphaColors.end()) {
const int alpha = attributes().hasAttribute(qsl("alpha")) ? attributes().value(qsl("alpha")).toInt() : 255;
pHost->*it.value() = QColor::fromString(readElementText());
(pHost->*it.value()).setAlpha(alpha);
return true;
}
return false;
}
bool XMLimport::readHostBorderElement(QMargins& borders, QStringView elementName)
{
if (elementName == qsl("borderTopHeight")) {
borders.setTop(readElementText().toInt());
return true;
}
if (elementName == qsl("borderBottomHeight")) {
borders.setBottom(readElementText().toInt());
return true;
}
if (elementName == qsl("borderLeftWidth")) {
borders.setLeft(readElementText().toInt());
return true;
}
if (elementName == qsl("borderRightWidth")) {
borders.setRight(readElementText().toInt());
return true;
}
return false;
}
bool XMLimport::readDefaultTrueBool(QString name)
{
return attributes().value(name) == YES || !attributes().hasAttribute(name);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
// returns the ID of the root imported trigger/group
int XMLimport::readTriggerPackage()
2009-02-06 03:39:14 +01:00
{
int parentItemID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2009-02-06 03:39:14 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
2009-02-06 03:39:14 +01:00
break;
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isStartElement()) {
if (name() == qsl("TriggerGroup") || name() == qsl("Trigger")) {
2011-05-28 02:13:53 +02:00
gotTrigger = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
parentItemID = readTrigger(mPackageName.isEmpty() ? nullptr : mpTrigger);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("TriggerPackage"));
2009-02-06 03:39:14 +01:00
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
}
return parentItemID;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
// imports a trigger and returns its ID - in case of a group, returns the ID
// of the top-level trigger group.
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readTrigger(TTrigger* pParent)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
{
auto pT = new TTrigger(pParent, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
pT->mModuleMember = true;
}
mpHost->getTriggerUnit()->registerTrigger(pT);
pT->setIsActive(attributes().value(qsl("isActive")) == YES);
pT->setIsFolder(attributes().value(qsl("isFolder")) == YES);
pT->setTemporary(attributes().value(qsl("isTempTrigger")) == YES);
pT->mIsMultiline = attributes().value(qsl("isMultiline")) == YES;
pT->mPerlSlashGOption = attributes().value(qsl("isPerlSlashGOption")) == YES;
pT->mIsColorizerTrigger = attributes().value(qsl("isColorizerTrigger")) == YES;
pT->mFilterTrigger = attributes().value(qsl("isFilterTrigger")) == YES;
pT->mSoundTrigger = attributes().value(qsl("isSoundTrigger")) == YES;
pT->mColorTrigger = attributes().value(qsl("isColorTrigger")) == YES;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
// Is this a "TriggerGroup" or a "Trigger"
const QString what = name().toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->setName(readElementText());
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
if (!pT->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readTrigger(...): ERROR: can not compile trigger's lua code for: " << pT->getName();
}
} else if (name() == qsl("packageName")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mPackageName = readElementText();
} else if (name() == qsl("triggerType")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mTriggerType = readElementText().toInt();
} else if (name() == qsl("conditonLineDelta")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mConditionLineDelta = readElementText().toInt();
} else if (name() == qsl("mStayOpen")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mStayOpen = readElementText().toInt();
} else if (name() == qsl("mCommand")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mCommand = readElementText();
} else if (name() == qsl("mFgColor")) {
Fix: correct warnings/errors found whilst working on Windows CI (#7224) #### Brief overview of PR changes/additions Whilst working on getting the Windows CI process to run in a MSYS2+Mingw-w64 environment on AppVeyor in both Qt 5 and 6 and both 32-bits and 64-bits (Qt6 only supports 64-Bit builds). I ran into a number of warnings, some of them about things deprecated in Qt 6.0 or later. This PR should eliminate all of them for our code (though there are a couple in upstream things). #### Motivation for adding to Mudlet Make the build process cleaner all around, especially with moving forward to Qt 6. #### Other info (issues closed, discussion etc) The use of `std::as_const(...)` requires C++17 but we have already mandated that. `qAsConst(...)` is deprecated in Qt 6. Some of the places where the above was being done also were missing the use of a `const` reference rather than the making of a constant copy of the iterated values; these have been fixed as well. A couple of Mudlet classes that I haven't yet cleaned up to move as much of the class initialisation to the header as possible were reporting initialisation ordering issue (`Host` and `TTimer`). I have fixed those but only in the region of the issues, more work there is desirable to clean up every remaining class - but I'm not allowed to leave "TODO:" comments around nowadays! :grinning: `(void) zip_error_to_str(char*, size_t, int, int))` has been obsoleted for a long time now, and I've finally put in something in a couple of places that will use the recommended replacement `(zip_error_t*) zip_get_error(zip*)` and dump the error message out to the OS console - which was not happening in the past. `(QString) QString::fromUtf16(...)` has been obsoleted and alternatives are suggested within the Qt documentation. I've used `QString::fromWCharArray(...)`. Whilst this compiles ***I am not 100% sure I have this correct and a second opinion on this change in `./src/mudlet.cpp` is desirable!*** Qt is renaming in Qt6 a few methods that otherwise function as before: * `(Qt::KeyboardModifiers) QDragEnterEvent::keyboardModifiers()` ==> `QDragEnterEvent::modifiers()` * `(Qt::KeyboardModifiers) QDragMoveEvent::keyboardModifiers()` ==> `QDragMoveEvent::modifiers()` * `(bool) QColor::isValidColor(const QString&)` ==> `(bool) QColor::isValidColorName(QAnyStringView)` * `(void) QColor::setNamedColor(const QString&)` ==> `(QColor) QColor::fromString(QAnyStringView)` * `(QString) QLocale::countryToString(Country)` ==> `(QString) QLocale::territoryToString(Territory)` Windows NTFS permissions checking was being done with a really low-level procedure which has been deprecated in Qt 6.6 and replaced with a slightly better (but also low-level) pair of functions: * `(bool) qEnableNtfsPermissionChecks()` * `(bool) qEnableNtfsPermissionChecks()` to do the same thing in almost the same way with a lesser risk of a "race-condition". There is a higher-level procedure involving the use of a new class `QNtfsPermissionCheckGuard` but that is a different way of doing things that is not a drop-in replacement AFAICT. There was an unhandled `case` (for `QTextToSpeech::State::Synthesizing`) in `(void) TLuaInterpreter::ttsStateChanged(QTextToSpeech::State)` - I've put in something to report that state but it is not clear that this, seemingly, transient state, needs anything extra than that. For instance, given that it looks to be associated with preparing a text to be spoken it might be reasonable to report the text involved as the `Speaking` state does... The point at which it was introduced is also unclear as that isn't documented! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2024-05-20 19:00:51 +00:00
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mFgColor.setNamedColor(readElementText());
} else if (name() == qsl("mBgColor")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mBgColor.setNamedColor(readElementText());
} else if (name() == qsl("colorTriggerFgColor")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mColorTriggerFgColor.setNamedColor(readElementText());
} else if (name() == qsl("colorTriggerBgColor")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mColorTriggerBgColor.setNamedColor(readElementText());
Fix: correct warnings/errors found whilst working on Windows CI (#7224) #### Brief overview of PR changes/additions Whilst working on getting the Windows CI process to run in a MSYS2+Mingw-w64 environment on AppVeyor in both Qt 5 and 6 and both 32-bits and 64-bits (Qt6 only supports 64-Bit builds). I ran into a number of warnings, some of them about things deprecated in Qt 6.0 or later. This PR should eliminate all of them for our code (though there are a couple in upstream things). #### Motivation for adding to Mudlet Make the build process cleaner all around, especially with moving forward to Qt 6. #### Other info (issues closed, discussion etc) The use of `std::as_const(...)` requires C++17 but we have already mandated that. `qAsConst(...)` is deprecated in Qt 6. Some of the places where the above was being done also were missing the use of a `const` reference rather than the making of a constant copy of the iterated values; these have been fixed as well. A couple of Mudlet classes that I haven't yet cleaned up to move as much of the class initialisation to the header as possible were reporting initialisation ordering issue (`Host` and `TTimer`). I have fixed those but only in the region of the issues, more work there is desirable to clean up every remaining class - but I'm not allowed to leave "TODO:" comments around nowadays! :grinning: `(void) zip_error_to_str(char*, size_t, int, int))` has been obsoleted for a long time now, and I've finally put in something in a couple of places that will use the recommended replacement `(zip_error_t*) zip_get_error(zip*)` and dump the error message out to the OS console - which was not happening in the past. `(QString) QString::fromUtf16(...)` has been obsoleted and alternatives are suggested within the Qt documentation. I've used `QString::fromWCharArray(...)`. Whilst this compiles ***I am not 100% sure I have this correct and a second opinion on this change in `./src/mudlet.cpp` is desirable!*** Qt is renaming in Qt6 a few methods that otherwise function as before: * `(Qt::KeyboardModifiers) QDragEnterEvent::keyboardModifiers()` ==> `QDragEnterEvent::modifiers()` * `(Qt::KeyboardModifiers) QDragMoveEvent::keyboardModifiers()` ==> `QDragMoveEvent::modifiers()` * `(bool) QColor::isValidColor(const QString&)` ==> `(bool) QColor::isValidColorName(QAnyStringView)` * `(void) QColor::setNamedColor(const QString&)` ==> `(QColor) QColor::fromString(QAnyStringView)` * `(QString) QLocale::countryToString(Country)` ==> `(QString) QLocale::territoryToString(Territory)` Windows NTFS permissions checking was being done with a really low-level procedure which has been deprecated in Qt 6.6 and replaced with a slightly better (but also low-level) pair of functions: * `(bool) qEnableNtfsPermissionChecks()` * `(bool) qEnableNtfsPermissionChecks()` to do the same thing in almost the same way with a lesser risk of a "race-condition". There is a higher-level procedure involving the use of a new class `QNtfsPermissionCheckGuard` but that is a different way of doing things that is not a drop-in replacement AFAICT. There was an unhandled `case` (for `QTextToSpeech::State::Synthesizing`) in `(void) TLuaInterpreter::ttsStateChanged(QTextToSpeech::State)` - I've put in something to report that state but it is not clear that this, seemingly, transient state, needs anything extra than that. For instance, given that it looks to be associated with preparing a text to be spoken it might be reasonable to report the text involved as the `Speaking` state does... The point at which it was introduced is also unclear as that isn't documented! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@hey.com>
2024-05-20 19:00:51 +00:00
#else
pT->mFgColor = QColor::fromString(readElementText());
} else if (name() == qsl("mBgColor")) {
pT->mBgColor = QColor::fromString(readElementText());
} else if (name() == qsl("colorTriggerFgColor")) {
pT->mColorTriggerFgColor = QColor::fromString(readElementText());
} else if (name() == qsl("colorTriggerBgColor")) {
pT->mColorTriggerBgColor = QColor::fromString(readElementText());
#endif
} else if (name() == qsl("mSoundFile")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mSoundFile = readElementText();
} else if (name() == qsl("regexCodeList")) {
// This and the next one ought to be combined into a single element
// in the next revision - sample code for "RegexCode" elements
// inside a "patterns" container (with a "size" attribute) is
// commented out in the XMLexporter class.
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readStringList(pT->mPatterns, what);
} else if (name() == qsl("regexCodePropertyList")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readIntegerList(pT->mPatternKinds, pT->getName(), what);
if (Q_UNLIKELY(pT->mPatterns.count() != pT->mPatternKinds.count())) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qWarning().nospace() << "XMLimport::readTrigger(...) ERROR: "
2021-08-22 08:01:05 +02:00
"mismatch in regexCode details for Trigger: "
<< pT->getName() << " there were " << pT->mPatterns.count() << " 'regexCodeList' sub-elements and " << pT->mPatternKinds.count()
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
<< " 'regexCodePropertyList' sub-elements so "
"something is broken!";
}
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
// Fixup the first 16 incorrect ANSI colour numbers from old
// code if there are any
if (!pT->mPatterns.isEmpty()) {
remapColorsToAnsiNumber(pT->mPatterns, pT->mPatternKinds);
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
}
} else if (name() == qsl("TriggerGroup") || name() == qsl("Trigger")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readTrigger(pT);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
2009-02-06 03:39:14 +01:00
}
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (!pT->setRegexCodeList(pT->mPatterns, pT->mPatternKinds)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readTrigger(...): ERROR: can not "
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
"initialize pattern list for trigger: "
<< pT->getName();
}
return pT->getID();
2009-02-06 03:39:14 +01:00
}
int XMLimport::readTimerPackage()
{
int lastImportedTimerID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("TimerGroup") || name() == qsl("Timer")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
gotTimer = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
lastImportedTimerID = readTimer(mPackageName.isEmpty() ? nullptr : mpTimer);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("TimerPackage"));
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
return lastImportedTimerID;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readTimer(TTimer* pParent)
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
{
auto pT = new TTimer(pParent, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->setIsFolder(attributes().value(qsl("isFolder")) == YES);
Refactor: store the Host name and TTimer Id in QTimer properties (#2480) Prevent crashes when using resetProfile() - which gets awkward if the code to be run that contains the resetProfile() call is itself going to be deleted by that call! This eliminates the need for a mudlet class multi-layer QMap: (QMap<Host*, QMap<QTimer*, TTimer*>>) mHostTimerMap which otherwise would be consulted to find the needed TTimer instance when a QTimer fired. This is advantageous because it avoids a whole extra level of complexity when adding or removing (especially temporary {and thus one- shot}) TTimers. It also corrects a confusing issue in that the Lua constructed temp timers are all initialised with the name "a" - instead they are given a more useful (for debugging) "newTempTimerWithoutAnId" when constructed in the TLuaInterpreter class until they are assigned the string form of their Id number when they are registered. The clean up code for `TTimer`s was also simplified by switching the container that held the pointers for `TTimer`s that were to be cleaned up from a `std::list<TTimer*>` to a `QSet<TTimer*>` which meant it was no longer necessary to search the whole list when adding a new one to prevent duplication as a set container inherently prevents duplicates. I found that it was feasible to remove (bool) TTimer::registerTimer() and move it's functionality into (bool) TimerUnit::registerTimer(TTimer*) - this is so there is one less function to ensure is called at the right time. Remove unused argument from method: * (bool) TTimer::canBeUnlocked(TTimer* pChild) ==> (bool) TTimer::canBeUnlocked() Also convert a pair of C style casts in Tree.h to a more appropriate C++ style. Also set some Q_LIKELY/Q_UNLIKELY macros to guide optimising compilers. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-04-12 21:49:22 +01:00
// This should not ever be set here as, by definition, temporary timers
// are not saved:
pT->setTemporary(attributes().value(qsl("isTempTimer")) == YES);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
Refactor: store the Host name and TTimer Id in QTimer properties (#2480) Prevent crashes when using resetProfile() - which gets awkward if the code to be run that contains the resetProfile() call is itself going to be deleted by that call! This eliminates the need for a mudlet class multi-layer QMap: (QMap<Host*, QMap<QTimer*, TTimer*>>) mHostTimerMap which otherwise would be consulted to find the needed TTimer instance when a QTimer fired. This is advantageous because it avoids a whole extra level of complexity when adding or removing (especially temporary {and thus one- shot}) TTimers. It also corrects a confusing issue in that the Lua constructed temp timers are all initialised with the name "a" - instead they are given a more useful (for debugging) "newTempTimerWithoutAnId" when constructed in the TLuaInterpreter class until they are assigned the string form of their Id number when they are registered. The clean up code for `TTimer`s was also simplified by switching the container that held the pointers for `TTimer`s that were to be cleaned up from a `std::list<TTimer*>` to a `QSet<TTimer*>` which meant it was no longer necessary to search the whole list when adding a new one to prevent duplication as a set container inherently prevents duplicates. I found that it was feasible to remove (bool) TTimer::registerTimer() and move it's functionality into (bool) TimerUnit::registerTimer(TTimer*) - this is so there is one less function to ensure is called at the right time. Remove unused argument from method: * (bool) TTimer::canBeUnlocked(TTimer* pChild) ==> (bool) TTimer::canBeUnlocked() Also convert a pair of C style casts in Tree.h to a more appropriate C++ style. Also set some Q_LIKELY/Q_UNLIKELY macros to guide optimising compilers. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-04-12 21:49:22 +01:00
// This clears the Tree<TTimer>::mUserActiveState flag so MUST be done
// BEFORE that flag is parsed:
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->getTimerUnit()->registerTimer(pT);
Refactor: store the Host name and TTimer Id in QTimer properties (#2480) Prevent crashes when using resetProfile() - which gets awkward if the code to be run that contains the resetProfile() call is itself going to be deleted by that call! This eliminates the need for a mudlet class multi-layer QMap: (QMap<Host*, QMap<QTimer*, TTimer*>>) mHostTimerMap which otherwise would be consulted to find the needed TTimer instance when a QTimer fired. This is advantageous because it avoids a whole extra level of complexity when adding or removing (especially temporary {and thus one- shot}) TTimers. It also corrects a confusing issue in that the Lua constructed temp timers are all initialised with the name "a" - instead they are given a more useful (for debugging) "newTempTimerWithoutAnId" when constructed in the TLuaInterpreter class until they are assigned the string form of their Id number when they are registered. The clean up code for `TTimer`s was also simplified by switching the container that held the pointers for `TTimer`s that were to be cleaned up from a `std::list<TTimer*>` to a `QSet<TTimer*>` which meant it was no longer necessary to search the whole list when adding a new one to prevent duplication as a set container inherently prevents duplicates. I found that it was feasible to remove (bool) TTimer::registerTimer() and move it's functionality into (bool) TimerUnit::registerTimer(TTimer*) - this is so there is one less function to ensure is called at the right time. Remove unused argument from method: * (bool) TTimer::canBeUnlocked(TTimer* pChild) ==> (bool) TTimer::canBeUnlocked() Also convert a pair of C style casts in Tree.h to a more appropriate C++ style. Also set some Q_LIKELY/Q_UNLIKELY macros to guide optimising compilers. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-04-12 21:49:22 +01:00
pT->setShouldBeActive(attributes().value(qsl("isActive")) == YES);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
pT->mModuleMember = true;
}
const QString what = name().toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->setName(readElementText());
} else if (name() == qsl("packageName")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mPackageName = readElementText();
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
if (!pT->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readTimer(...): ERROR: can not compile timer's lua code for: " << pT->getName();
}
} else if (name() == qsl("command")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->mCommand = readElementText();
} else if (name() == qsl("time")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
pT->setTime(QTime::fromString(readElementText(), "hh:mm:ss.zzz"));
} else if (name() == qsl("TimerGroup") || name() == qsl("Timer")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readTimer(pT);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
}
}
}
if (!pT->mpParent && pT->shouldBeActive()) {
pT->setIsActive(true);
pT->enableTimer(pT->getID());
}
return pT->getID();
}
int XMLimport::readAliasPackage()
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
{
int lastImportedAliasID = -1;
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("AliasGroup") || name() == qsl("Alias")) {
gotAlias = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
lastImportedAliasID = readAlias(mPackageName.isEmpty() ? nullptr : mpAlias);
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("AliasPackage"));
}
}
}
return lastImportedAliasID;
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readAlias(TAlias* pParent)
{
auto pT = new TAlias(pParent, mpHost);
mpHost->getAliasUnit()->registerAlias(pT);
pT->setIsActive(attributes().value(qsl("isActive")) == YES);
pT->setIsFolder(attributes().value(qsl("isFolder")) == YES);
if (module) {
pT->mModuleMember = true;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
const QString what = name().toString();
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
pT->setName(readElementText());
} else if (name() == qsl("packageName")) {
pT->mPackageName = readElementText();
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
if (!pT->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readAlias(...): ERROR: can not compile alias's lua code for: " << pT->getName();
}
} else if (name() == qsl("command")) {
pT->mCommand = readElementText();
} else if (name() == qsl("regex")) {
pT->setRegexCode(readElementText());
} else if (name() == qsl("AliasGroup") || name() == qsl("Alias")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readAlias(pT);
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
}
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
return pT->getID();
}
2009-02-06 03:39:14 +01:00
int XMLimport::readActionPackage()
{
int lastImportedActionID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
2009-02-06 03:39:14 +01:00
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("ActionGroup") || name() == qsl("Action")) {
gotAction = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
lastImportedActionID = readAction(mPackageName.isEmpty() ? nullptr : mpAction);
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("ActionPackage"));
}
}
}
return lastImportedActionID;
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readAction(TAction* pParent)
{
auto pT = new TAction(pParent, mpHost);
pT->setIsFolder(attributes().value(qsl("isFolder")) == YES);
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setIsPushDownButton(attributes().value(qsl("isPushButton")) == YES);
pT->setButtonFlat(attributes().value(qsl("isFlatButton")) == YES);
pT->mUseCustomLayout = attributes().value(qsl("useCustomLayout")) == YES;
mpHost->getActionUnit()->registerAction(pT);
pT->setIsActive(attributes().value(qsl("isActive")) == YES);
if (module) {
pT->mModuleMember = true;
}
const QString what = name().toString();
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setName(readElementText());
} else if (name() == qsl("packageName")) {
2011-05-28 23:04:59 +02:00
pT->mPackageName = readElementText();
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
if (!pT->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readAction(...): ERROR: can not compile action's lua code for: " << pT->getName();
}
} else if (name() == qsl("css")) {
pT->css = readElementText();
} else if (name() == qsl("commandButtonUp")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setCommandButtonUp(readElementText());
} else if (name() == qsl("commandButtonDown")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setCommandButtonDown(readElementText());
} else if (name() == qsl("icon")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setIcon(readElementText());
} else if (name() == qsl("orientation")) {
pT->mOrientation = readElementText().toInt();
} else if (name() == qsl("location")) {
pT->mLocation = readElementText().toInt();
} else if (name() == qsl("buttonRotation")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setButtonRotation(readElementText().toInt());
} else if (name() == qsl("sizeX")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setSizeX(readElementText().toInt());
} else if (name() == qsl("sizeY")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
pT->setSizeY(readElementText().toInt());
} else if (name() == qsl("mButtonState")) {
// We now use a boolean but file must use original "1" (false)
// or "2" (true) for backward compatibility
pT->mButtonState = (readElementText().toInt() == 2);
} else if (name() == qsl("buttonColor")) {
Infrastructure: move away from constructor initialisation lists - part 2 (#5937) For classes from "T2*" to "TM*" (approximately)... I have steered away from using `{}` to initialise simple, POD data types in favour of explicitly stating what their default values are. Also: * remove unused `(QColor) TAction::mButtonColor` and it's associated getter and setter. Also remove the save code from the `XMLexport` class and ensure it is skipped and silently discarded in the load code in `XMLimport`. * Make `private` some members of the `TFlipButton` class that probably weren't ever intended to be `public` * Remove unneeded named argument for `lua_State*` type in many (but not all) function declarations in `TLuaInterpreter.h` file - they aren't needed and whether an `L` was present or not seems to entirely down to the whim of the individual coder of each function...! * Rejig some of the initiliasations in the `TLuaInterpreter` class * Refactor a chunk of code n the `TMap` class used to (re)initialise the 16 colours user settable from the preferences dialogue to a method: `(void) TMap::restore16ColorSet()` - so that it can be used in three other places as well as the constuctor. * Remove unused `(int) T2DMap::gzoom`. * Add missing `TMediaData.h` file to qmake project file. Note: `QPointer<T>` instances do NOT need initialisation, they are automagically instantiated with a `nullptr` value. Revised to change code to fit in with PR #6133 There were some pre-Qt 5.14.0 version checks that are no longer relevant. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
2022-06-27 20:36:51 +01:00
// Not longer present/used, skip over it if it is still in file:
skipCurrentElement();
} else if (name() == qsl("buttonColumn")) {
Improve: make filler widget size in toolbars user settable (#9332) #### Brief overview of PR changes/additions Replace code that tried to offset the first button in a toolbar by one extra "space" every time it is saved by a settable variable that can add zero to one less than the number of rows/columns that a toolbar has. The maximum value for this and the control in the editor is automatically set to be that one less every time the number of rows/columns is changed, and the control disabled should the other one be set to less that 2. It seems that it is possible to set the number of rows/columns to zero and it looks as though, many years ago, it was possible to use that zero value to disable the use of a `QGridLayout` for the toolbar and instead allow the buttons to have a manually/custom layout. The code with reproducing the manual layout seems to have persisted but that to allow it to be modified looks to have disappeared. That bares further investigation. #### Motivation for adding to Mudlet With the introduction of autosaving in the editor it is no longer reasonable to change the layout every time something in a toolbar is edited causing things to be saved - and relying on the end-user not ever touching the arrangement in the editor window. Instead this knob can be used to set it explicitly. There is no provision in the Lua API for this "knob" in this PR because the current Button/Menu/Toolbar implementation in the Lua subsystem is seriously borked/incomplete. A major overhaul of that is intended for a future PR! #### Other info (issues closed, discussion etc) Also: * Make members of `TAction` class that have getters/setters `private:`. * Make the text in the editor for toolbars: "Number of columns/rows (depending on orientation):" actually change to match the setting for the selected orientation. * Move the `QLineEdit` to show the file name for the button icon into the appropriate `QGroupBox` and add a `QLabel` for it - but keep them hidden for now. This feature was disabled (without reason?) in 4e651d55fd7a73af24fe66ae3d85e9e5b13a1fc5 which removed the button that was used to select a file to provide an icon however the reproduction of icons on buttons and menus was never removed. Previously the `QLineEdit` was used in a read-only mode to display (until it was shrunk to a zero size before this change) the file chosen. I intend to re-enable this functionality in the future. --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2026-08-04 23:18:32 +01:00
// The above ought to have been plural!
pT->setButtonColumns(readElementText().toInt());
} else if (name() == qsl("buttonFillerOffset")) {
pT->setButtonFillerOffset(readElementText().toInt());
} else if (name() == qsl("posX")) {
pT->mPosX = readElementText().toInt();
} else if (name() == qsl("posY")) {
pT->mPosY = readElementText().toInt();
} else if (name() == qsl("ActionGroup") || name() == qsl("Action")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readAction(pT);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
}
}
}
return pT->getID();
}
int XMLimport::readScriptPackage()
{
int lastImportedScriptID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("ScriptGroup") || name() == qsl("Script")) {
2011-05-28 02:13:53 +02:00
gotScript = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
lastImportedScriptID = readScript(mPackageName.isEmpty() ? nullptr : mpScript);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("ScriptPackage"));
}
}
}
return lastImportedScriptID;
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readScript(TScript* pParent)
{
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
auto script = new TScript(pParent, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
script->setIsFolder(attributes().value(qsl("isFolder")) == YES);
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
mpHost->getScriptUnit()->registerScript(script);
script->setIsActive(attributes().value(qsl("isActive")) == YES);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
script->mModuleMember = true;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
const QString what = name().toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
script->mName = readElementText();
} else if (name() == qsl("packageName")) {
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
script->mPackageName = readElementText();
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
if (!script->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace().noquote() << "XMLimport::readScript(...) ERROR - can not compile script's lua code for \"" << script->getName() << "\"; reason: " << script->getError() << ".";
}
} else if (name() == qsl("eventHandlerList")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readStringList(script->mEventHandlerList, what);
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
script->setEventHandlerList(script->mEventHandlerList);
} else if (name() == qsl("ScriptGroup") || name() == qsl("Script")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readScript(script);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
}
}
}
Add Lua tests to CI (#3795) * Add a Ubuntu build * Install homebrew dependencies only on macOS * Add Linux dependencies separate * Don't stop other builds on fail * Install libzip-dev on Linux * Sudo please * Try installing libglu1-mesa-dev * Install Pulse dev libraries * Add a workaround for Lua linking * Correct YAML * Back to a single line * Debug locations of libraries * Correct an extra / * Build Mudlet with tracing * Try -GNinja Multi-Config * Try not specifying a generator * Add link information against libdl.so as well (#33) * Add link information against libdl.so as well * Remove (harmful?) lua library path definition * Show built output in the end * Added a run tests flag * Try appending gcc argument as well * Debug plugin loading * Use a single, generic compiler line * Remove the x's * Install libxkbcommon-x11-0 * Try launching Achaea profile * Update .github/workflows/build-mudlet.yml Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com> * Try taking a screenshot of what's running * Fix YAML syntax * Clarify the step name * Take a screenshot even on build 'time out' * Install imagemagick * Fix whitespaces * Upgrade to latest 1.5 of the xvfb action * Pre-set environment variables to be used * Increase the timeout * Run with the self-test profile * Re-enable mudlet.org's connection info * Mock test runs * Add an installing debug echo * Debug with tmate * Show error when script couldn't be loaded * Print all script compile errors * Setup tmate at the end * Add debug echoes * Move Mudlet to the right location * Split out packaging steps * Cleanup * Auto-run tests * Install busted as well * Fix setup() call * Log everything sent to all consoles * Actually log everything printed * Pass in the test location * Comment out a crash * Tidier console print message * Echo cleanup * Better echo style * Wrap closeMudlet in a timer to avoid a crash * Comment out mSpellDic crash as well * Set environment variable when test failed * Fail workflow when tests fail * Write to GITHUB_ENV properly * Add setEnv * Make use of setEnv * Launch tmate * Write to file instead * Add comments * Improve error message * Remove tmate * Fix merge error * Add the new --mirror option * Don't deploy Windows builds * Only check Lua tests when we need to * Update job name * Remove unusued setEnv Co-authored-by: keneanung <keneanung@googlemail.com> Co-authored-by: Damian Monogue <3660+demonnic@users.noreply.github.com>
2021-09-30 09:56:03 +02:00
return script->getID();
}
int XMLimport::readKeyPackage()
{
int lastImportedKeyID = -1;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("KeyGroup") || name() == qsl("Key")) {
2011-05-28 02:13:53 +02:00
gotKey = true;
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
lastImportedKeyID = readKey(mPackageName.isEmpty() ? nullptr : mpKey);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("KeyPackage"));
}
}
}
return lastImportedKeyID;
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
int XMLimport::readKey(TKey* pParent)
{
auto pT = new TKey(pParent, mpHost);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
mpHost->getKeyUnit()->registerKey(pT);
pT->setIsActive(attributes().value(qsl("isActive")) == YES);
pT->setIsFolder(attributes().value(qsl("isFolder")) == YES);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (module) {
pT->mModuleMember = true;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
}
const QString what = name().toString();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("name")) {
pT->setName(readElementText());
} else if (name() == qsl("packageName")) {
2011-05-28 23:04:59 +02:00
pT->mPackageName = readElementText();
} else if (name() == qsl("script")) {
const QString tempScript = readScriptElement();
if (!pT->setScript(tempScript)) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
qDebug().nospace() << "XMLimport::readKey(...): ERROR: can not compile key's lua code for: " << pT->getName();
}
} else if (name() == qsl("command")) {
pT->mCommand = readElementText();
} else if (name() == qsl("keyCode")) {
pT->setKeyCode(readElementText().toInt());
} else if (name() == qsl("keyModifier")) {
pT->setKeyModifiers(readElementText().toInt());
} else if (name() == qsl("KeyGroup") || name() == qsl("Key")) {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readKey(pT);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(what);
}
}
}
return pT->getID();
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
void XMLimport::readModulesDetailsMap(QMap<QString, QStringList>& map)
{
QString key;
QStringList entry;
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("key")) {
key = readElementText();
} else if (name() == qsl("filepath")) {
entry << readElementText();
} else if (name() == qsl("zipSync")) {
entry << readElementText();
} else if (name() == qsl("globalSave")) {
2021-11-07 22:15:20 +01:00
if (entry.size() < 2) {
entry << readElementText();
} else {
skipCurrentElement();
}
} else if (name() == qsl("priority")) {
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
// The last expected detail for the entry - so store this
// completed entry into the QMap
entry << readElementText();
map[key] = entry;
entry.clear();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(qsl("ModulesDetailsMap"));
}
}
}
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
void XMLimport::readStringList(QStringList& list, const QString& whatIsParent)
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("string")) {
list << readElementText();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(whatIsParent);
2009-02-06 03:39:14 +01:00
}
}
}
}
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
void XMLimport::readIntegerList(QList<int>& list, const QString& parentName, const QString& whatIsParent)
{
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
while (!atEnd()) {
readNext();
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("integer")) {
const QString numberText = readElementText();
bool ok = false;
const int num = numberText.toInt(&ok, 10);
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
if (Q_LIKELY(!numberText.isEmpty() && ok)) {
switch (num) {
case REGEX_SUBSTRING:
[[fallthrough]];
case REGEX_PERL:
[[fallthrough]];
case REGEX_BEGIN_OF_LINE_SUBSTRING:
[[fallthrough]];
case REGEX_EXACT_MATCH:
[[fallthrough]];
case REGEX_LUA_CODE:
[[fallthrough]];
case REGEX_LINE_SPACER:
[[fallthrough]];
case REGEX_COLOR_PATTERN:
[[fallthrough]];
case REGEX_PROMPT:
list << num;
break;
default:
mpHost->postMessage(
qsl("[ ERROR ] - \"%1\" as a number when reading the 'regexCodePropertyList' element of the 'Trigger' or 'TriggerGroup' element \"%2\" cannot be understood by this "
"version of Mudlet, is it from a later version? Converting it to a SUBSTRING type so the data can be shown but it will probably not work as expected.")
.arg(numberText, parentName));
list << REGEX_SUBSTRING; //Set it to the default type
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
qWarning(
R"(XMLimport::readIntegerList(...) ERROR: unable to convert: "%s" to a number when reading the 'regexCodePropertyList' element of the 'Trigger' or 'TriggerGroup' element "%s"!)",
2017-04-12 19:09:47 -07:00
numberText.toUtf8().constData(),
parentName.toUtf8().constData());
mpHost->postMessage(qsl("[ ERROR ] - Unable to convert: \"%1\" to a number when reading the 'regexCodePropertyList' element of the 'Trigger' or 'TriggerGroup' element \"%2\"!")
.arg(numberText, parentName));
list << REGEX_SUBSTRING; //Just assume most common one
}
BugFix: bad parsing of map room/exit sizes + tidy XML import/export c… (#372) * BugFix: bad parsing of map room/exit sizes + tidy XML import/export classes Floating point numbers used for the 2D map room and exit-line sizes were included in the XML file format twice and being read as integers when one, at least, is a decimal number in range 0.1 to 1.1 so was being set to zero when read for 9 out 11 cases. The miss-spelt duplicate "commandSeperator" element is no longer written as the parsing code can handle an element missing when reading the Host part of the XML file. The XMLimport class will silently ignore the above duplicate details so as to avoid producing qDebug() messages about them when reading them in XML files produced from older code. I have taken the opportunity to clean up the code layout in these two classes, the XMLexport had some code block indentation issues and the XMLimport class some pointless if() code. I also have added in error detection/reporting code in the export code so that if errors arise in method function calls they are reported up the caller chain and the XMLWriter aborts as soon as an error is detected. I have also added QDebug() reporting for all instances where lua scripts are inserting into the Mudlet items as they are loaded where they were only previously being done for some types of item. It was also possible to eliminate the redundant (QString) XMLexport::mType member and the unneeded XMLexport(Host *, bool) C'tor. I also renamed: * (void) XMLimport::readMapList(QMap<QString, QStringList> & ) ==> (void) XMLimport::readModulesDetailsMap(QMap<QString, QStringList> & ) to reduce any confusion over what it applies to (a QMap not the profile's Map!) I have held off on applying QStringLiteral(...) wrappers around all the string literals in these classes as that would just make the change-set even larger on this occasion but it is something to be done at a later stage IMHO. Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: further fixes revealed when porting BugFix portion to "release_30" I note I had some details incorrect or not completely done when porting the bug correction bits to the other "release_30" active branch. Also some comments were worth revising so that they match ones left in that branch. * Removed misspelt "commandSeperator" sub-element of the "Host" element and the associated (QString) Host::mCommandSeperator which was unused and duplicated the (QString) Host::mCommandSeperator member...! * Tweaked some QDebug() message texts for a uniform style and to correct some amendments missed when they were copied from one method to another. * Added an argument to the XMLimport::readIntegerList(...) to pass the name of the parent trigger for use if/when the error condition of having an invalid (not a number) as an element that encodes the type of the trigger condition for a particular condition. This is justified because under those conditions qFatal() is used {probably because it is the only QDebug class method that WILL be detectable on a WINDOWS platform for a RELEASE build} unfortunately it will KILL the Mudlet application - so it behoves Mudlet to report what killed it when it does die through this! * Tweaked some comments to match versions in the release_30 bug_fix only version of this Pull Request. * Rename the argument to void XMLimport::readHostPackage(Host *) from pT to pHost as the latter name is more prevalent elsewhere in the application. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-02-27 03:56:18 +00:00
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement(whatIsParent);
}
}
}
}
// This will be a string representation of a decimal float with three places of
// decimals
void XMLimport::getVersionString(QString& versionString)
{
versionString = QString::number((mVersionMajor * 1000 + mVersionMinor) / 1000.0, 'f', 3);
}
BugFix: allows most ASCII control characters to be used/saved in Lua Code (#995) * BugFix: allows most ASCII control characters to be used/saved in Lua code We use XML to save Mudlet game data including the scripts that contain Lua code for all of the Mudlet item {Alias|Button|Key|Timer|Script|Trigger} but because the former (at version 1.0 which is all that the Qt library code handles) prohibits all but Horizontal Tab, Carriage Return and Line Feed out of the range of ASCII control codes it means that a user trying to embed a raw string containing, say, the ESC code (0x1b) will either lose their code for just the item containing that code OR everything that follows it in the file that it is being loaded from. As that could be the game save data this may will cause data loss. This commit allows all but the ASCII NULL (`\0`) character code to be stored as it replaces the remaining control codes with a pair of other Unicode code-points that can be safely stored, that is (U+FFFC) the Unicode Object Replacement Character code-point followed by one of the code-points from the Control Picture Symbol range. The former is not a visible character in normal circumstances but the latter (if present in a font) is typically a two or three letters in a diagonal line in a single grapheme that has the same two or three letters used to abbreviate an ASCII Control code in, say, visible table representations. The chances of the Object Replacement Character occurring in ANY document is virtually zero so the use for this purpose should be "safe" in this context and using the Control Picture Character does have the nice feature in that viewing a saved file with them in does suggest which character is being used - and the chances of them being used in, even a Mudlet script, otherwise is vanishingly small in my opinion. Note that NO attempt is made to handle the ASCII NUL character as that is also, symbolically the end of a C/C++ string normally and it would be confusing to the Lua interpreter even though the Qt QString text handling system could tolerate having such characters in positions other than at the end of a QString. During the development of this system to "Escape" these codes I did experiment with the use of "XML Entities" to represent them - such as "&ESC;" to stand in for the ASCII 0x1B character. However the Qt process to insert such elements into the required a costly splitting the script text up into fragments without any of the codes to be escaped so that each code could then be injected into the QXmlStreamWriter stream interleaved with the text fragments that surrounds them and whilst this proved to be possible I then found that the process that then took the entities and substituted in the original ASCII control codes when the script data was read with the QXmlStreamReader failed to work because the QXmlStreamEntityResolver applied the same character code restrictions onto the replacement text - which is exactly not what was wanted! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: fix wrong symbol used for DEL control code I used the code for U+2471 {CIRCLED NUMBER EIGHTEEN} instead of U+2421 {SYMBOL FOR DELETE} to encode the ASCII Delete code (0x7F, 127) - this fix does mean that any files saved using the code of the Pull Request before it is applied will not convert any of the DEL codes in a saved XML file back to the correct value automatically but I do not anticipate this will cause significant issues...! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-05-14 09:44:44 +01:00
QString XMLimport::readScriptElement()
{
QString localScript = readElementText();
if (Error() != NoError) {
qDebug() << "XMLimport::readScriptElement() ERROR:" << errorString();
BugFix: allows most ASCII control characters to be used/saved in Lua Code (#995) * BugFix: allows most ASCII control characters to be used/saved in Lua code We use XML to save Mudlet game data including the scripts that contain Lua code for all of the Mudlet item {Alias|Button|Key|Timer|Script|Trigger} but because the former (at version 1.0 which is all that the Qt library code handles) prohibits all but Horizontal Tab, Carriage Return and Line Feed out of the range of ASCII control codes it means that a user trying to embed a raw string containing, say, the ESC code (0x1b) will either lose their code for just the item containing that code OR everything that follows it in the file that it is being loaded from. As that could be the game save data this may will cause data loss. This commit allows all but the ASCII NULL (`\0`) character code to be stored as it replaces the remaining control codes with a pair of other Unicode code-points that can be safely stored, that is (U+FFFC) the Unicode Object Replacement Character code-point followed by one of the code-points from the Control Picture Symbol range. The former is not a visible character in normal circumstances but the latter (if present in a font) is typically a two or three letters in a diagonal line in a single grapheme that has the same two or three letters used to abbreviate an ASCII Control code in, say, visible table representations. The chances of the Object Replacement Character occurring in ANY document is virtually zero so the use for this purpose should be "safe" in this context and using the Control Picture Character does have the nice feature in that viewing a saved file with them in does suggest which character is being used - and the chances of them being used in, even a Mudlet script, otherwise is vanishingly small in my opinion. Note that NO attempt is made to handle the ASCII NUL character as that is also, symbolically the end of a C/C++ string normally and it would be confusing to the Lua interpreter even though the Qt QString text handling system could tolerate having such characters in positions other than at the end of a QString. During the development of this system to "Escape" these codes I did experiment with the use of "XML Entities" to represent them - such as "&ESC;" to stand in for the ASCII 0x1B character. However the Qt process to insert such elements into the required a costly splitting the script text up into fragments without any of the codes to be escaped so that each code could then be injected into the QXmlStreamWriter stream interleaved with the text fragments that surrounds them and whilst this proved to be possible I then found that the process that then took the entities and substituted in the original ASCII control codes when the script data was read with the QXmlStreamReader failed to work because the QXmlStreamEntityResolver applied the same character code restrictions onto the replacement text - which is exactly not what was wanted! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: fix wrong symbol used for DEL control code I used the code for U+2471 {CIRCLED NUMBER EIGHTEEN} instead of U+2421 {SYMBOL FOR DELETE} to encode the ASCII Delete code (0x7F, 127) - this fix does mean that any files saved using the code of the Pull Request before it is applied will not convert any of the DEL codes in a saved XML file back to the correct value automatically but I do not anticipate this will cause significant issues...! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-05-14 09:44:44 +01:00
}
if (mVersionMajor > 1 || (mVersionMajor == 1 && mVersionMinor > 0)) {
BugFix: allows most ASCII control characters to be used/saved in Lua Code (#995) * BugFix: allows most ASCII control characters to be used/saved in Lua code We use XML to save Mudlet game data including the scripts that contain Lua code for all of the Mudlet item {Alias|Button|Key|Timer|Script|Trigger} but because the former (at version 1.0 which is all that the Qt library code handles) prohibits all but Horizontal Tab, Carriage Return and Line Feed out of the range of ASCII control codes it means that a user trying to embed a raw string containing, say, the ESC code (0x1b) will either lose their code for just the item containing that code OR everything that follows it in the file that it is being loaded from. As that could be the game save data this may will cause data loss. This commit allows all but the ASCII NULL (`\0`) character code to be stored as it replaces the remaining control codes with a pair of other Unicode code-points that can be safely stored, that is (U+FFFC) the Unicode Object Replacement Character code-point followed by one of the code-points from the Control Picture Symbol range. The former is not a visible character in normal circumstances but the latter (if present in a font) is typically a two or three letters in a diagonal line in a single grapheme that has the same two or three letters used to abbreviate an ASCII Control code in, say, visible table representations. The chances of the Object Replacement Character occurring in ANY document is virtually zero so the use for this purpose should be "safe" in this context and using the Control Picture Character does have the nice feature in that viewing a saved file with them in does suggest which character is being used - and the chances of them being used in, even a Mudlet script, otherwise is vanishingly small in my opinion. Note that NO attempt is made to handle the ASCII NUL character as that is also, symbolically the end of a C/C++ string normally and it would be confusing to the Lua interpreter even though the Qt QString text handling system could tolerate having such characters in positions other than at the end of a QString. During the development of this system to "Escape" these codes I did experiment with the use of "XML Entities" to represent them - such as "&ESC;" to stand in for the ASCII 0x1B character. However the Qt process to insert such elements into the required a costly splitting the script text up into fragments without any of the codes to be escaped so that each code could then be injected into the QXmlStreamWriter stream interleaved with the text fragments that surrounds them and whilst this proved to be possible I then found that the process that then took the entities and substituted in the original ASCII control codes when the script data was read with the QXmlStreamReader failed to work because the QXmlStreamEntityResolver applied the same character code restrictions onto the replacement text - which is exactly not what was wanted! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: fix wrong symbol used for DEL control code I used the code for U+2471 {CIRCLED NUMBER EIGHTEEN} instead of U+2421 {SYMBOL FOR DELETE} to encode the ASCII Delete code (0x7F, 127) - this fix does mean that any files saved using the code of the Pull Request before it is applied will not convert any of the DEL codes in a saved XML file back to the correct value automatically but I do not anticipate this will cause significant issues...! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-05-14 09:44:44 +01:00
// This is NOT the original version, so it will have control characters
// encoded up using Object Replacement and Control Symbol (for relevant ASCII control code) code-points
localScript.replace(qsl("\xFFFC\x2401"), QChar('\x01')); // SOH
localScript.replace(qsl("\xFFFC\x2402"), QChar('\x02')); // STX
localScript.replace(qsl("\xFFFC\x2403"), QChar('\x03')); // ETX
localScript.replace(qsl("\xFFFC\x2404"), QChar('\x04')); // EOT
localScript.replace(qsl("\xFFFC\x2405"), QChar('\x05')); // ENQ
localScript.replace(qsl("\xFFFC\x2406"), QChar('\x06')); // ACK
localScript.replace(qsl("\xFFFC\x2407"), QChar('\x07')); // BEL
localScript.replace(qsl("\xFFFC\x2408"), QChar('\x08')); // BS
localScript.replace(qsl("\xFFFC\x240B"), QChar('\x0B')); // VT
localScript.replace(qsl("\xFFFC\x240C"), QChar('\x0C')); // FF
localScript.replace(qsl("\xFFFC\x240E"), QChar('\x0E')); // SS
localScript.replace(qsl("\xFFFC\x240F"), QChar('\x0F')); // SI
localScript.replace(qsl("\xFFFC\x2410"), QChar('\x10')); // DLE
localScript.replace(qsl("\xFFFC\x2411"), QChar('\x11')); // DC1
localScript.replace(qsl("\xFFFC\x2412"), QChar('\x12')); // DC2
localScript.replace(qsl("\xFFFC\x2413"), QChar('\x13')); // DC3
localScript.replace(qsl("\xFFFC\x2414"), QChar('\x14')); // DC4
localScript.replace(qsl("\xFFFC\x2415"), QChar('\x15')); // NAK
localScript.replace(qsl("\xFFFC\x2416"), QChar('\x16')); // SYN
localScript.replace(qsl("\xFFFC\x2417"), QChar('\x17')); // ETB
localScript.replace(qsl("\xFFFC\x2418"), QChar('\x18')); // CAN
localScript.replace(qsl("\xFFFC\x2419"), QChar('\x19')); // EM
localScript.replace(qsl("\xFFFC\x241A"), QChar('\x1A')); // SUB
localScript.replace(qsl("\xFFFC\x241B"), QChar('\x1B')); // ESC
localScript.replace(qsl("\xFFFC\x241C"), QChar('\x1C')); // FS
localScript.replace(qsl("\xFFFC\x241D"), QChar('\x1D')); // GS
localScript.replace(qsl("\xFFFC\x241E"), QChar('\x1E')); // RS
localScript.replace(qsl("\xFFFC\x241F"), QChar('\x1F')); // US
localScript.replace(qsl("\xFFFC\x2421"), QChar('\x7F')); // DEL
BugFix: allows most ASCII control characters to be used/saved in Lua Code (#995) * BugFix: allows most ASCII control characters to be used/saved in Lua code We use XML to save Mudlet game data including the scripts that contain Lua code for all of the Mudlet item {Alias|Button|Key|Timer|Script|Trigger} but because the former (at version 1.0 which is all that the Qt library code handles) prohibits all but Horizontal Tab, Carriage Return and Line Feed out of the range of ASCII control codes it means that a user trying to embed a raw string containing, say, the ESC code (0x1b) will either lose their code for just the item containing that code OR everything that follows it in the file that it is being loaded from. As that could be the game save data this may will cause data loss. This commit allows all but the ASCII NULL (`\0`) character code to be stored as it replaces the remaining control codes with a pair of other Unicode code-points that can be safely stored, that is (U+FFFC) the Unicode Object Replacement Character code-point followed by one of the code-points from the Control Picture Symbol range. The former is not a visible character in normal circumstances but the latter (if present in a font) is typically a two or three letters in a diagonal line in a single grapheme that has the same two or three letters used to abbreviate an ASCII Control code in, say, visible table representations. The chances of the Object Replacement Character occurring in ANY document is virtually zero so the use for this purpose should be "safe" in this context and using the Control Picture Character does have the nice feature in that viewing a saved file with them in does suggest which character is being used - and the chances of them being used in, even a Mudlet script, otherwise is vanishingly small in my opinion. Note that NO attempt is made to handle the ASCII NUL character as that is also, symbolically the end of a C/C++ string normally and it would be confusing to the Lua interpreter even though the Qt QString text handling system could tolerate having such characters in positions other than at the end of a QString. During the development of this system to "Escape" these codes I did experiment with the use of "XML Entities" to represent them - such as "&ESC;" to stand in for the ASCII 0x1B character. However the Qt process to insert such elements into the required a costly splitting the script text up into fragments without any of the codes to be escaped so that each code could then be injected into the QXmlStreamWriter stream interleaved with the text fragments that surrounds them and whilst this proved to be possible I then found that the process that then took the entities and substituted in the original ASCII control codes when the script data was read with the QXmlStreamReader failed to work because the QXmlStreamEntityResolver applied the same character code restrictions onto the replacement text - which is exactly not what was wanted! Signed-off-by: Stephen Lyons <slysven@virginmedia.com> * Revise: fix wrong symbol used for DEL control code I used the code for U+2471 {CIRCLED NUMBER EIGHTEEN} instead of U+2421 {SYMBOL FOR DELETE} to encode the ASCII Delete code (0x7F, 127) - this fix does mean that any files saved using the code of the Pull Request before it is applied will not convert any of the DEL codes in a saved XML file back to the correct value automatically but I do not anticipate this will cause significant issues...! Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2017-05-14 09:44:44 +01:00
}
return localScript;
}
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
// Unlike the reverse operation in the XMLexport this can modify the supplied patternList:
void XMLimport::remapColorsToAnsiNumber(QStringList& patternList, const QList<int>& typeList)
{
// The regexp is slightly modified compared to the one we once used to allow
// it to capture a '-' sign as part of the color numbers as we use -2 for
// ignored which was/is/will not handled by code before Mudlet 3.17.x (and
// we might have more negative numbers in the future!)
const QRegularExpression regex = QRegularExpression(qsl("FG(-?\\d+)BG(-?\\d+)"));
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
QMutableStringListIterator itPattern(patternList);
QListIterator<int> itType(typeList);
while (itPattern.hasNext() && itType.hasNext()) {
if (itType.next() == REGEX_COLOR_PATTERN) {
const QRegularExpressionMatch match = regex.match(itPattern.next());
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
// Although we define two '('...')' capture groups the count/size is
// 3 (0 is the whole string)!
if (match.capturedTexts().size() == 3) {
bool isFgOk = false;
bool isBgOk = false;
int ansifg = TTrigger::scmIgnored;
int ansibg = TTrigger::scmIgnored;
int fg = match.captured(1).toInt(&isFgOk);
if (!isFgOk) {
qDebug() << "XMLimport::remapColorsToAnsiNumber(...) ERROR - failed to extract FG color code from pattern text:" << itPattern.peekPrevious()
<< " setting colour to default foreground";
fg = TTrigger::scmDefault;
} else {
// clang-format off
switch (fg) {
case -2: ansifg = TTrigger::scmIgnored; break; // Ignored colour - not handled by old code
case 0: ansifg = TTrigger::scmDefault; break; // Default colour
case 1: ansifg = 8; break; // Light black (dark gray)
case 2: ansifg = 0; break; // Black
case 3: ansifg = 9; break; // Light red
case 4: ansifg = 1; break; // Red
case 5: ansifg = 10; break; // Light green
case 6: ansifg = 2; break; // Green
case 7: ansifg = 11; break; // Light yellow
case 8: ansifg = 3; break; // Yellow
case 9: ansifg = 12; break; // Light blue
case 10: ansifg = 4; break; // Blue
case 11: ansifg = 13; break; // Light magenta
case 12: ansifg = 5; break; // Magenta
case 13: ansifg = 14; break; // Light cyan
case 14: ansifg = 6; break; // Cyan
case 15: ansifg = 15; break; // Light white
case 16: ansifg = 7; break; // White (light gray)
default:
ansifg = fg;
}
// clang-format on
}
int bg = match.captured(2).toInt(&isBgOk);
if (!isBgOk) {
qDebug() << "XMLimport::remapColorsToAnsiNumber(...) ERROR - failed to extract BG color code from pattern text:" << itPattern.peekPrevious()
<< " setting colour to default background";
bg = TTrigger::scmDefault;
} else {
// clang-format off
switch (bg) {
case -2: ansibg = TTrigger::scmIgnored; break; // Ignored colour - not handled by old code
case 0: ansibg = TTrigger::scmDefault; break; // Default colour
case 1: ansibg = 8; break; // Light black (dark gray)
case 2: ansibg = 0; break; // Black
case 3: ansibg = 9; break; // Light red
case 4: ansibg = 1; break; // Red
case 5: ansibg = 10; break; // Light green
case 6: ansibg = 2; break; // Green
case 7: ansibg = 11; break; // Light yellow
case 8: ansibg = 3; break; // Yellow
case 9: ansibg = 12; break; // Light blue
case 10: ansibg = 4; break; // Blue
case 11: ansibg = 13; break; // Light magenta
case 12: ansibg = 5; break; // Magenta
case 13: ansibg = 14; break; // Light cyan
case 14: ansibg = 6; break; // Cyan
case 15: ansibg = 15; break; // Light white
case 16: ansibg = 7; break; // White (light gray)
default:
ansibg = bg;
}
// clang-format on
}
// Use a different string than before so that we can be certain
// we have fixed up all cases where it is used - and it is more
// understandable if it gets revealed in the Editor!
itPattern.setValue(TTrigger::createColorPatternText(ansifg, ansibg));
}
} else {
2021-08-22 08:01:05 +02:00
// Must advance the pattern iterator if it isn't a colour pattern
Refactor: clean up TBuffer text format aspects (#1840) This is the edited summary of a squash and merge of 14 commits: Adds support for SGR Reverse (swap foreground and background colours) "7"/"27" for On/Off and SGR Overline "53"/"55" for On/Off Remove unused cruft: * (void) TTextEdit::drawFrame(QPainter&, const QRect&) * (void) TTextEdit::updateLastLine * const QChar cLF & cSPACE in TBuffer (as it happens they are completely unused and redundant as the enum QChar::SpecialCharacter provides QChar::LineFeed and QChar::Space to provide the same constants) * (QTime) TBuffer::mTime * (void) TConsole::echoUserWindow(const QString&) * (QPoint) TBuffer::insert(QPoint&, const QString&, int, int, int, int, int, int, bool, bool, bool, bool) * (void) TConsole::printDebug(...) functionally the same as one type of (void) TConsole::print(...) just with a different order of arguments. Convert #define constants TCHAR_BOLD etc. into a QFLag/enum TChar::AttributeFlags which is declared and capable of QFlag OR operations. Refactor a number of methods that take lots of bools and ints as individual formatting options and colour components to take single TChar::AttributeFlags and one or two QColors instead. Remove a large number of (int) colour value component values as member variables in TBuffer as they are not needed. Convert highly repetitive intermediate methods to setBold, setItalics etc. to take a (combinations allowed) TChar::Attribute flag value instead. Convert 2x3 int as colour components (r,g,b) in TColorTable defined in TTrigger class to a pair of QColors. Remove unused QString argument from: * (void) mudlet::setLink(...) * (void) TConsole::setLink(...) Remove unused QColor argument from: * (inline void) TTextEdit::drawCharacters(...) Refactor arguments in: *(QString) TBuffer::bufferToHtml(QPoint P1, QPoint P2, bool allowedTimestamps, int spacePadding = 0) to: (QString) TBuffer::bufferToHtml(const bool showTimeStamp = false, const int row = -1, const int endColumn = -1, const int startColumn = 0, int spacePadding = 0) Convert to const references some method arguments. Add TBuffer::set[BF]gColor(...) overloads that take a QColor argument. Add selection state methods select()/deselect()/isSelected() const methods to TChar class to hide/separate the selection process from the formatting effect. (TChar::Reverse tracks the ANSI SGR reverse colour attribute and its effect is EX-ORed with the (bool) TChar::mIsSelected flag). Add a new tempAnsiColorTrigger lua function that, unlike tempColorTrigger uses the correct ANSIcolors in the range 0-15 - although the original also handles the 256 colour range in the 16-255 correctly those first 16 values are miss-mapped and it is not possible to change them without breakage. Adds 256-color support to Editor GUI for color triggers - and allows choosing the default (unmodified) fore or background colors to match one (the previous did not) and also allows one of the fore or background color to be ignored so only the other is considered. The ignored color case is saved in the profile data and can exported but MAY not work in previous Mudlet versions which cannot handle the value used! It is also reported as an error to have a color trigger with both fore and background ignored in both the lua functions and in the GUI. Also: Fixed a code structure issue in TLuaInterpreter::debug() which would not work correctly if there was more than one value on the lua stack to print out. This will close issues #477 and #703. Converted some `QObject::connect` calls to the new Qt5 compile time version. Removed an unused `TTrigger*` argument from `dlgColorTrigger::setupBasicButtons(...)`. Removed an unused flag: * `(bool) TConsole::mSaveLayoutRequested Also spotted some dead code from abandoned attempt to support blinking, some reordering that a new version of Qt spotted as needed in the TBuffer and TChar constructor initialisation lists, and a operator precedence item that could be clarified with an addition pair of `(`...`)`s. A previous error in the prior PR that this one is attempting to replace had a problem in HTML generation that I reproduced here and which needed the same fix (a missing escaped `"` mark). An upgraded Qt Creator pointed out to me some initiliser list issues in `TBuffer` and `TConsole`; and some C-style casts in some font settings in the latter class. Remove a debugging output line that is not useful now and will be spammy. Modernise a triplet of QObject::connect(...) calls that will otherwise clash harder when merged into development after "upgrade-to-qt5-connect" PR has also been merged into the main branch. Also: * add some explanation/help text to the dlgColorTrigger dialog. * revise the text explaining the formula (232 + grey scale value 0..23) used for colours from the 24 grey-scale part of the 256 colour range. * add some tool-tips to parts of the dlgColorTrigger dialog. * add a generic static method to the mudlet class to provide a consistent and re-usable "HTML" wrapper around text - which will be particularly useful for tool-tip generation. Revise: change colour trigger UI to hide colours 16-255 by default This follows a suggestion from a peer in the review process. Update: add Wiki documentation link comment Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
2019-01-28 23:23:53 +00:00
itPattern.next();
}
}
}
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
void XMLimport::readStopWatchMap()
{
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("stopwatch")) {
const int watchId = attributes().value(qsl("id")).toInt();
improve: improve memory safety by using smart pointers (#9239) ### Refactor: replace raw pointer ownership with smart pointers across core subsystems #### Brief overview of PR changes/additions Replaces raw pointer ownership patterns with `std::unique_ptr` and `std::map` across several core subsystems: - **Host**: `mStopWatchMap` (`QMap<int, stopWatch*>` → `std::map<int, unique_ptr<stopWatch>>`), `profileShortcuts` (`QMap<QString, QKeySequence*>` → `std::map<QString, unique_ptr<QKeySequence>>`). Removes `qDeleteAll` in destructor and `delete mMMCPServer`. - **TMap**: `mpRoomDB` raw pointer → `unique_ptr` - **VarUnit**: `base` raw pointer → `unique_ptr` - **TTrigger**: condition map storage converted to `unique_ptr`, destructor simplified - **discord**: handler and presence maps converted from raw pointer `QMap` to `unique_ptr` + `std::map` - **Updater**: `mFeed` and `mUpdateDialog` converted to `unique_ptr` #### Motivation for adding to Mudlet These patterns were identified as sources of memory leaks and potential use-after-free bugs. Using smart pointers makes ownership explicit, eliminates manual cleanup code, and ensures correct destruction even on early-exit paths. #### Other info (issues closed, discussion etc) sorry this one is still pretty big, but most of the changes are the same for each thing so reviewing them together probably makes sense. sadly there isn't much to see here other than no slow uptick of heap size :-[ Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:42:09 +12:00
auto pStopWatch = std::make_unique<stopWatch>();
pStopWatch->setName(attributes().value(qsl("name")).toString());
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
pStopWatch->mIsPersistent = true;
pStopWatch->mIsInitialised = true;
if (attributes().value(qsl("running")) == YES) {
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
pStopWatch->mIsRunning = true;
// The stored value is the point in epoch time that the
// stopwatch appears to have been started so we need to
// make that into a QDateTime that is the equivalent:
pStopWatch->mEffectiveStartDateTime.setMSecsSinceEpoch(attributes().value(qsl("effectiveStartDateTimeEpochMSecs")).toLongLong());
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
} else {
pStopWatch->mIsRunning = false;
pStopWatch->mElapsedTime = attributes().value(qsl("elapsedDateTimeMSecs")).toLongLong();
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
}
improve: improve memory safety by using smart pointers (#9239) ### Refactor: replace raw pointer ownership with smart pointers across core subsystems #### Brief overview of PR changes/additions Replaces raw pointer ownership patterns with `std::unique_ptr` and `std::map` across several core subsystems: - **Host**: `mStopWatchMap` (`QMap<int, stopWatch*>` → `std::map<int, unique_ptr<stopWatch>>`), `profileShortcuts` (`QMap<QString, QKeySequence*>` → `std::map<QString, unique_ptr<QKeySequence>>`). Removes `qDeleteAll` in destructor and `delete mMMCPServer`. - **TMap**: `mpRoomDB` raw pointer → `unique_ptr` - **VarUnit**: `base` raw pointer → `unique_ptr` - **TTrigger**: condition map storage converted to `unique_ptr`, destructor simplified - **discord**: handler and presence maps converted from raw pointer `QMap` to `unique_ptr` + `std::map` - **Updater**: `mFeed` and `mUpdateDialog` converted to `unique_ptr` #### Motivation for adding to Mudlet These patterns were identified as sources of memory leaks and potential use-after-free bugs. Using smart pointers makes ownership explicit, eliminates manual cleanup code, and ensures correct destruction even on early-exit paths. #### Other info (issues closed, discussion etc) sorry this one is still pretty big, but most of the changes are the same for each thing so reviewing them together probably makes sense. sadly there isn't much to see here other than no slow uptick of heap size :-[ Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:42:09 +12:00
mpHost->mStopWatchMap[watchId] = std::move(pStopWatch);
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
// A dummy read as there should not be any text for this element:
readElementText();
} else {
Fix: Unknown nested elements in XML packages elements (like Host etc.) will cause erasure of settings (#5895) <!-- Keep the title short & concise so anyone non-technical can understand it, the title appears in PTB changelogs --> #### Brief overview of PR changes/additions Having unknown elements in XML, might cause clearing of already properly set elements. This shouldn't happen, as we're flattening Host package, but still good to fix that issue. Example: ```xml <Host autoClearCommandLineAfterSend="no" HighlightHistory="yes" printCommand="yes" USE_IRE_DRIVER_BUGFIX="no" mUSE_FORCE_LF_AFTER_PROMPT="no" mUSE_UNIX_EOL="no" mNoAntiAlias="no" mEchoLuaErrors="yes" runAllKeyMatches="no" AmbigousWidthGlyphsToBeWide="auto" mRawStreamDump="yes" mIsLoggingTimestamps="no" ...> <name>Test</name> <mInstalledPackages /> ... <unknowns> <unknown>1</unknown> <unknown>2</unknown> </unknowns> <stopwatches /> </Host> ``` initially will set all values correctly in Host object, second run will happen, like those values are never set, because it will treat `unknowns` node just like it was `Host` node. #### Motivation for adding to Mudlet Fixing #### Other info (issues closed, discussion etc) Same applies to other elements, like Triggers, Aliases etc. #### Release post highlight <!-- Use this space if you wish to write a short statement or example for inclusion in the release post for the next release. --> --------- Signed-off-by: Stephen Lyons <slysven@virginmedia.com> Co-authored-by: Stephen Lyons <slysven@virginmedia.com>
2023-02-16 12:08:34 +01:00
readUnknownElement("stopwatches");
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
}
}
}
}
void XMLimport::readMMCPOptions()
{
mpHost->mMMCPChatName = attributes().value(qsl("chatName")).toString();
mpHost->mMMCPChatPort = attributes().value(qsl("chatPort")).toUShort();
mpHost->mMMCPChatPrefix = attributes().value(qsl("chatPrefix")).toString();
mpHost->mMMCPAutostartServer = attributes().value(qsl("autostartServer")) == YES;
mpHost->mMMCPAllowPeekRequests = attributes().value(qsl("allowPeekRequests")) == YES;
mpHost->mMMCPPrefixEmotes = attributes().value(qsl("prefixEmotes")) == YES;
mpHost->mMMCPAddChatMessageNewline = attributes().value(qsl("chatMessageNewline")) == YES;
mpHost->mMMCPAutoAcceptCalls = attributes().value(qsl("autoAcceptCalls")) == YES;
mpHost->mMMCPShowSnoopInMainConsole = attributes().value(qsl("snoopInMain")) == YES;
// MMCP is a self-closing tag, need to call readNext to move along..
readNext();
}
void XMLimport::readMapInfoContributor()
{
mpHost->mMapInfoContributors.insert(readElementText());
}
void XMLimport::readLegacyMapInfoContributors()
{
while (!atEnd()) {
readNext();
if (isEndElement()) {
break;
}
if (isStartElement()) {
if (name() == qsl("mapInfoContributor")) {
mpHost->mMapInfoContributors.insert(readElementText());
}
}
}
Enhance: overhaul stopwatches redux (#3224) Redo_Enhance: overhaul stopwatches This PR is a rework of the original PR #2516 squash-and-merged with the bugfix that I proposed as PR #3162 but which became difficult to apply when the original PR was eliminated from the development branch because it has been reverted from the 4.2.0 release and then that had been merged into the development branch! This PR allows stopwatches to be stopped and read at any time afterwards, for any number of times. It also: * allows stopwatches to be destroyed - so ID numbers WILL get reused - with a Lua (bool) destroyStopWatch((int) id) function. * allows them to be marked as persistent so that they are saved with the profile and reloaded again - if they were running then they will continue to increment when the profile is not loaded so they can be used to real time events outside of the profile/session; this uses a new Lua function (bool) setStopWatchPersistence((int) id, (bool) setPersistent). * allows them to be adjusted (even so they become negative) so can be used to count down as well as count up time - whether the stopwatch concerned is running or not. * have error messages that conform to our current style * have more run-time handling - most actions that produce no effect will advise that this is the case - e.g. stopping a stopwatch that was NOT running... * can handle periods of time longer than a day - the previous implementation wrapped around after 24 hours. * should not affected by DST changes - OS permitting. * the Lua API also gains a getStopWatches() function that returns a table with the id numbers as keys and values as tables of: * (bool) isRunning * (bool) isPersistent * (string) name * (table) elapsedTime - containing broken down time: * (bool) negative * (int) days * (int) hours (0 to 23) * (int) minutes (0 to 59) * (int) seconds (0 to 59) * (int) milliSeconds (0 to 999) * (float) decimalSeconds floating point value of whole of the time in seconds (can be negative!) * allows stop watches to be named - which is useful as then they can be identified in scripts; this means that all the stop watch functions can now take a name string as well as a numeric argument. Using an empty string will access the first (lowest id) stopwatch that does not have a name and the createStopWatch() function will accept an optional string argument as a name. For simplicity each name must be unique and this is enforced for that function and the added setStopWatchName(id or name, newName) function. The latter will also accept an empty string as either the first or second argument; in the first case it will assign the name to the first unnamed stopwatch and the second will clear the name of the specified one. * added getStopWatchBrokenDownTime(...) which returns the same broken down elements in a table for a single specified timer (day count; hours; minutes; seconds; milliseconds and whether the time is positive or negative {when preset with a negative adjustment and used as a count down})... During debugging I found out that the process of loading an existing profile that contained createStopWatch() calls was creating them during the testing/loading phase so I had to add extra code to prevent that function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~ *revised to use a different, new, flag: `Host::mBlockStopWatchCreation` which is cleared earlier in the loading sequence* is true. Then, when testing the resetProfile() function I found that the same thing was happening AND that the non-persistent stopwatches needed to be removed as well - which is now solved by also preventing stopwatch creation whilst (bool) Host::mResetProfile is set and by running a new method (void) Host::removeAllNonPersistentStopWatches()! This thus allows stopwatches to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done). The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64) originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in that I had thought it adjusted the QDateTime it was called upon whereas it returns a reference to the adjusted value - so needed to be invoked in a different manner which was already being done in the original PR. QString stopWatch::getElapsedDayTimeString() const made use of int for some intermediate local variables but on Windows platforms the int type may be 32-bit long and thus not big enough to contain 64-bit values - and some other locals can be much shorter because of the limits that the code places on their values but will give compiler warnings without static_cast <T>. Use std::chrono_literals to specify some needed time intervals rather than large long integer literal constants. Refactor a block of code used to generate the broken down time as a Lua table so that two instances are handled by a single helper function. Additional code (the bug fix) has been included to provide backwards-compatibility for Lua startStopWatch(id) function which recreates prior start stop-watch behaviour when it is created: The prior form of startStopWatch(...) would reset and restart the indicated stopwatch each time that it was called. This is not really compatible with the revised functionality which allows the recorded time to be adjusted even before the stopwatch is first used. To allow existing scripts to continue to experience the same API this commit adds an optional second boolean argument to the startStopWatch(...) call ONLY WHEN the first argument is an id number and NOT a string name. If the second argument is omitted (as it will be when using older scripts) or is true then each time the function is used the stopwatch will be reset and restarted. Just in case the same behaviour ***is*** wanted with stop watch created with a **name** then a second boolean `true` will start the stopwatch from zero. This PR replaces (and thus will) close #3162 . A separate commit was appended and squashed in to reduce a code duplication pointed out by CodeFactor: Created a single function that is used to do the same thing in four separate stop-watch functions. Signed-off by: Stephen Lyons <slysven@virginmedia.com
2019-11-30 16:43:26 +00:00
}
void XMLimport::readProfileShortcut()
{
auto key = attributes().value(qsl("key"));
auto sequenceString = readElementText();
improve: improve memory safety by using smart pointers (#9239) ### Refactor: replace raw pointer ownership with smart pointers across core subsystems #### Brief overview of PR changes/additions Replaces raw pointer ownership patterns with `std::unique_ptr` and `std::map` across several core subsystems: - **Host**: `mStopWatchMap` (`QMap<int, stopWatch*>` → `std::map<int, unique_ptr<stopWatch>>`), `profileShortcuts` (`QMap<QString, QKeySequence*>` → `std::map<QString, unique_ptr<QKeySequence>>`). Removes `qDeleteAll` in destructor and `delete mMMCPServer`. - **TMap**: `mpRoomDB` raw pointer → `unique_ptr` - **VarUnit**: `base` raw pointer → `unique_ptr` - **TTrigger**: condition map storage converted to `unique_ptr`, destructor simplified - **discord**: handler and presence maps converted from raw pointer `QMap` to `unique_ptr` + `std::map` - **Updater**: `mFeed` and `mUpdateDialog` converted to `unique_ptr` #### Motivation for adding to Mudlet These patterns were identified as sources of memory leaks and potential use-after-free bugs. Using smart pointers makes ownership explicit, eliminates manual cleanup code, and ensures correct destruction even on early-exit paths. #### Other info (issues closed, discussion etc) sorry this one is still pretty big, but most of the changes are the same for each thing so reviewing them together probably makes sense. sadly there isn't much to see here other than no slow uptick of heap size :-[ Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-05 16:42:09 +12:00
if (auto it = mpHost->profileShortcuts.find(key.toString()); it != mpHost->profileShortcuts.end()) {
QKeySequence sequence = !sequenceString.isEmpty() ? QKeySequence(sequenceString) : QKeySequence();
it->second->swap(sequence);
}
}