/
XMLexport.cpp
1317 lines (1153 loc) · 61.7 KB
/
XMLexport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016-2017 by Ian Adkins - ieadkins@gmail.com *
* Copyright (C) 2017-2022 by Stephen Lyons - slysven@virginmedia.com *
* *
* 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 "XMLexport.h"
#include "Host.h"
#include "LuaInterface.h"
#include "TAction.h"
#include "TAlias.h"
#include "TConsole.h"
#include "TKey.h"
#include "TScript.h"
#include "TTimer.h"
#include "TTrigger.h"
#include "VarUnit.h"
#include "mudlet.h"
#include "pre_guard.h"
#include <QtConcurrent>
#include <QFile>
#include <sstream>
#include "post_guard.h"
XMLexport::XMLexport( Host * pH )
: mpHost(pH)
, mpTrigger(nullptr)
, mpTimer(nullptr)
, mpAlias(nullptr)
, mpAction(nullptr)
, mpScript(nullptr)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TTrigger * pT )
: mpHost(nullptr)
, mpTrigger(pT)
, mpTimer(nullptr)
, mpAlias(nullptr)
, mpAction(nullptr)
, mpScript(nullptr)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TTimer * pT )
: mpHost(nullptr)
, mpTrigger(nullptr)
, mpTimer(pT)
, mpAlias(nullptr)
, mpAction(nullptr)
, mpScript(nullptr)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TAlias * pT )
: mpHost(nullptr)
, mpTrigger(nullptr)
, mpTimer(nullptr)
, mpAlias(pT)
, mpAction(nullptr)
, mpScript(nullptr)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TAction * pT )
: mpHost(nullptr)
, mpTrigger(nullptr)
, mpTimer(nullptr)
, mpAlias(nullptr)
, mpAction(pT)
, mpScript(nullptr)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TScript * pT )
: mpHost(nullptr)
, mpTrigger(nullptr)
, mpTimer(nullptr)
, mpAlias(nullptr)
, mpAction(nullptr)
, mpScript(pT)
, mpKey(nullptr)
{
}
XMLexport::XMLexport( TKey * pT )
: mpHost(nullptr)
, mpTrigger(nullptr)
, mpTimer(nullptr)
, mpAlias(nullptr)
, mpAction(nullptr)
, mpScript(nullptr)
, mpKey(pT)
{
}
void XMLexport::writeModuleXML(const QString& moduleName, const QString& fileName, bool async)
{
auto pHost = mpHost;
auto mudletPackage = writeXmlHeader();
auto triggerPackage = mudletPackage.append_child("TriggerPackage");
//we go a level down for all these functions so as to not infinitely nest the module
for (auto& it : pHost->mTriggerUnit.mTriggerRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (!it->isTemporary() && it->mModuleMember) {
writeTrigger(it, triggerPackage);
}
}
auto timerPackage = mudletPackage.append_child("TimerPackage");
for (auto& it : pHost->mTimerUnit.mTimerRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (!it->isTemporary() && it->mModuleMember) {
writeTimer(it, timerPackage);
}
}
auto aliasPackage = mudletPackage.append_child("AliasPackage");
for (auto& it : pHost->mAliasUnit.mAliasRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (!it->isTemporary() && it->mModuleMember) {
writeAlias(it, aliasPackage);
}
}
auto actionPackage = mudletPackage.append_child("ActionPackage");
for (auto& it : pHost->mActionUnit.mActionRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (it->mModuleMember) {
writeAction(it, actionPackage);
}
}
auto scriptPackage = mudletPackage.append_child("ScriptPackage");
for (auto& it : pHost->mScriptUnit.mScriptRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (it->mModuleMember) {
writeScript(it, scriptPackage);
}
}
auto keyPackage = mudletPackage.append_child("KeyPackage");
for (auto& it : pHost->mKeyUnit.mKeyRootNodeList) {
if (!it || it->mPackageName != moduleName) {
continue;
}
if (!it->isTemporary() && it->mModuleMember) {
writeKey(it, keyPackage);
}
}
auto helpPackage = mudletPackage.append_child("HelpPackage");
if (pHost->moduleHelp.contains(moduleName) && pHost->moduleHelp.value(moduleName).contains(qsl("helpURL"))) {
helpPackage.append_child("helpURL").text().set(pHost->moduleHelp.value(moduleName).value(qsl("helpURL")).toUtf8().constData());
} else {
helpPackage.append_child("helpURL").text().set("");
}
if (async) {
auto future = QtConcurrent::run(this, &XMLexport::saveXml, fileName);
auto watcher = new QFutureWatcher<bool>;
QObject::connect(watcher, &QFutureWatcher<bool>::finished, mpHost, [=]() { mpHost->xmlSaved(fileName); });
watcher->setFuture(future);
saveFutures.append(future);
} else {
saveXml(fileName);
mpHost->xmlSaved(fileName);
}
}
void XMLexport::exportHost(const QString& filename_pugi_xml)
{
auto mudletPackage = writeXmlHeader();
writeHost(mpHost, mudletPackage);
auto future = QtConcurrent::run(this, &XMLexport::saveXml, filename_pugi_xml);
auto watcher = new QFutureWatcher<bool>;
QObject::connect(watcher, &QFutureWatcher<bool>::finished, mpHost, [=]() { mpHost->xmlSaved(qsl("profile")); });
watcher->setFuture(future);
saveFutures.append(future);
}
// credit: https://stackoverflow.com/a/29752943/72944
void inline XMLexport::replaceAll(std::string& source, const std::string& from, const std::string& to)
{
std::string newString;
newString.reserve(source.length()); // avoids a few memory allocations
std::string::size_type lastPos = 0;
std::string::size_type findPos;
while (std::string::npos != (findPos = source.find(from, lastPos))) {
newString.append(source, lastPos, findPos - lastPos);
newString += to;
lastPos = findPos + from.length();
}
// Care for the rest after last occurrence
newString += source.substr(lastPos);
source.swap(newString);
}
// sanitize non-printable characters for backwards & forward compatibility
// work qxml which is stuck at 1.0 and doesn't support properly
// encoding them. See https://github.com/Mudlet/Mudlet/issues/500
void XMLexport::sanitizeForQxml(std::string& output)
{
QMap<std::string, std::string> replacements{
{"", "\uFFFC\u2401"}, // SOH
{"", "\uFFFC\u2401"}, // SOH
{"", "\uFFFC\u2402"}, // STX
{"", "\uFFFC\u2402"}, // STX
{"", "\uFFFC\u2403"}, // ETX
{"", "\uFFFC\u2403"}, // ETX
{"", "\uFFFC\u2404"}, // EOT
{"", "\uFFFC\u2404"}, // EOT
{"", "\uFFFC\u2405"}, // ENQ
{"", "\uFFFC\u2405"}, // ENQ
{"", "\uFFFC\u2406"}, // ACK
{"", "\uFFFC\u2406"}, // ACK
{"", "\uFFFC\u2407"}, // BEL
{"", "\uFFFC\u2407"}, // BEL
{"", "\uFFFC\u2408"}, // BS
{"", "\uFFFC\u2408"}, // BS
{"", "\uFFFC\u240B"}, // VT
{"", "\uFFFC\u240C"}, // FF
{"", "\uFFFC\u240E"}, // SS
{"", "\uFFFC\u240F"}, // SI
{" ", "\uFFFC\u2410"}, // DLE
{"", "\uFFFC\u2411"}, // DC1
{"", "\uFFFC\u2412"}, // DC2
{"", "\uFFFC\u2413"}, // DC3
{"", "\uFFFC\u2414"}, // DC4
{"", "\uFFFC\u2415"}, // NAK
{"", "\uFFFC\u2416"}, // SYN
{"", "\uFFFC\u2417"}, // ETB
{"", "\uFFFC\u2418"}, // CAN
{"", "\uFFFC\u2419"}, // EM
{"", "\uFFFC\u241A"}, // SUB
{"", "\uFFFC\u241B"}, // ESC
{"", "\uFFFC\u241C"}, // FS
{"", "\uFFFC\u241D"}, // GS
{"", "\uFFFC\u241E"}, // RS
{"", "\uFFFC\u241F"}, // US
{"", "\uFFFC\u2421"}, // DEL
};
// Look for each replacement in data and if not present remove it from the
// list of things to replace
QMutableMapIterator<std::string, std::string> itReplacement(replacements);
while (itReplacement.hasNext()) {
itReplacement.next();
if (output.find(itReplacement.key()) == std::string::npos) {
itReplacement.remove();
}
}
if (!replacements.isEmpty()) {
// There is at least one thing left in the QMap of replacements and we
// can use the same iterator if we reset it to the start of the
// remaining replacements:
itReplacement.toFront();
while (itReplacement.hasNext()) {
itReplacement.next();
replaceAll(output, itReplacement.key(), itReplacement.value());
}
}
}
bool XMLexport::saveXml(const QString& fileName)
{
QFile file(fileName);
if (!file.open(QFile::WriteOnly)) {
qDebug().noquote().nospace() << "XMLexport::saveXml(\"" << fileName << "\") ERROR - failed to open file, reason: " << file.errorString() << ".";
return false;
}
bool result = saveXmlFile(file);
if (!result) {
if (file.error() != QFile::NoError) {
// Error reason was related to QFile:
qDebug().noquote().nospace() << "XMLexport::saveXml(\"" << fileName << "\") ERROR - failed to save package, reason: " << file.errorString() << ".";
} else {
// Error was due to failure in document preparation
qDebug().noquote().nospace() << "XMLexport::saveXml(\"" << fileName << "\") ERROR - failed to save package, reason: XML document preparation failure.";
}
}
file.close();
return result;
}
// This has been factored out to a separate method from saveXml(const QString&)
// because there are situations where we have a QFile instance already and
// just passing a filename and then creating another QFile instance on the
// same file in the filesystem is less than optimum.
// TODO: Refactor dlgTriggerEditor::slot_export() {at least} to call this method instead of saveXml(const QString&)
bool XMLexport::saveXmlFile(QFile& file)
{
std::stringstream saveStringStream(std::ios::out);
// Remember, the mExportDoc is the data in the form of a pugi::xml_document
// instance - the save method needs a stream that implements the
// std::ostream interface into which it can push the data:
mExportDoc.save(saveStringStream);
// We need to do our own replacement of ASCII control characters that are
// not valid in XML version 1.0 and that means we cannot use the pugixml
// file methods as it does that in a different way which is not helpful
// as we do not use that library for READING the XML files - so convert
// the data to a std::string :
std::string output(saveStringStream.str());
// Then do the control character replacement:
sanitizeForQxml(output);
// Now we can use Qt's file handling which does handle non-Latin1 named
// files - which MinGW's STL file handling (on Windows platform) does not:
file.write(output.data());
return file.error() == QFile::NoError;
}
QString XMLexport::saveXml()
{
std::stringstream saveStringStream(std::ios::out);
std::string output;
mExportDoc.save(saveStringStream);
output = saveStringStream.str();
sanitizeForQxml(output);
return QString::fromStdString(output);
}
void XMLexport::writeHost(Host* pHost, pugi::xml_node mudletPackage)
{
auto hostPackage = mudletPackage.append_child("HostPackage");
auto host = hostPackage.append_child("Host");
// Some of the data items being stored are simple numbers or other texts
// that can be expressed solely with the Latin1 character encoding so that
// can be used compared to the more complex Utf8 one needed otherwise:
host.append_attribute("autoClearCommandLineAfterSend") = pHost->mAutoClearCommandLineAfterSend ? "yes" : "no";
host.append_attribute("HighlightHistory") = pHost->mHighlightHistory ? "yes" : "no";
host.append_attribute("printCommand") = pHost->mPrintCommand ? "yes" : "no";
host.append_attribute("USE_IRE_DRIVER_BUGFIX") = pHost->mUSE_IRE_DRIVER_BUGFIX ? "yes" : "no";
host.append_attribute("mUSE_FORCE_LF_AFTER_PROMPT") = pHost->mUSE_FORCE_LF_AFTER_PROMPT ? "yes" : "no";
host.append_attribute("mUSE_UNIX_EOL") = pHost->mUSE_UNIX_EOL ? "yes" : "no";
host.append_attribute("mNoAntiAlias") = pHost->mNoAntiAlias ? "yes" : "no";
host.append_attribute("mEchoLuaErrors") = pHost->mEchoLuaErrors ? "yes" : "no";
host.append_attribute("runAllKeyMatches") = pHost->getKeyUnit()->mRunAllKeyMatches ? "yes" : "no";
host.append_attribute("AmbigousWidthGlyphsToBeWide") = pHost->mAutoAmbigousWidthGlyphsSetting ? "auto" : (pHost->mWideAmbigousWidthGlyphs ? "yes" : "no");
// FIXME: Change to a string or integer property when possible to support more
// than false (perhaps 0 or "PlainText") or true (perhaps 1 or "HTML") in the
// future - phpBB code might be useful if it can be done.
host.append_attribute("mRawStreamDump") = pHost->mIsNextLogFileInHtmlFormat ? "yes" : "no";
host.append_attribute("mIsLoggingTimestamps") = pHost->mIsLoggingTimestamps ? "yes" : "no";
host.append_attribute("logDirectory") = pHost->mLogDir.toUtf8().constData();
host.append_attribute("logFileName") = pHost->mLogFileName.toUtf8().constData();
host.append_attribute("logFileNameFormat") = pHost->mLogFileNameFormat.toUtf8().constData();
host.append_attribute("mAlertOnNewData") = pHost->mAlertOnNewData ? "yes" : "no";
host.append_attribute("mFORCE_NO_COMPRESSION") = pHost->mFORCE_NO_COMPRESSION ? "yes" : "no";
host.append_attribute("mFORCE_GA_OFF") = pHost->mFORCE_GA_OFF ? "yes" : "no";
host.append_attribute("mFORCE_SAVE_ON_EXIT") = pHost->mFORCE_SAVE_ON_EXIT ? "yes" : "no";
host.append_attribute("mEnableGMCP") = pHost->mEnableGMCP ? "yes" : "no";
host.append_attribute("mEnableMSSP") = pHost->mEnableMSSP ? "yes" : "no";
host.append_attribute("mEnableMSP") = pHost->mEnableMSP ? "yes" : "no";
host.append_attribute("mEnableMSDP") = pHost->mEnableMSDP ? "yes" : "no";
host.append_attribute("mMapStrongHighlight") = pHost->mMapStrongHighlight ? "yes" : "no";
host.append_attribute("mEnableSpellCheck") = pHost->mEnableSpellCheck ? "yes" : "no";
bool enableUserDictionary;
bool useSharedDictionary;
mpHost->getUserDictionaryOptions(enableUserDictionary, useSharedDictionary);
host.append_attribute("mEnableUserDictionary") = enableUserDictionary ? "yes" : "no";
host.append_attribute("mUseSharedDictionary") = useSharedDictionary ? "yes" : "no";
if (pHost->mMapInfoContributors.isEmpty()) {
host.append_attribute("mShowInfo") = "no";
}
host.append_attribute("mAcceptServerGUI") = pHost->mAcceptServerGUI ? "yes" : "no";
host.append_attribute("mAcceptServerMedia") = pHost->mAcceptServerMedia ? "yes" : "no";
host.append_attribute("mMapperUseAntiAlias") = pHost->mMapperUseAntiAlias ? "yes" : "no";
host.append_attribute("mMapperShowRoomBorders") = pHost->mMapperShowRoomBorders ? "yes" : "no";
host.append_attribute("mFORCE_MXP_NEGOTIATION_OFF") = pHost->mFORCE_MXP_NEGOTIATION_OFF ? "yes" : "no";
host.append_attribute("mFORCE_CHARSET_NEGOTIATION_OFF") = pHost->mFORCE_CHARSET_NEGOTIATION_OFF ? "yes" : "no";
host.append_attribute("enableTextAnalyzer") = pHost->mEnableTextAnalyzer ? "yes" : "no";
host.append_attribute("mRoomSize") = QString::number(pHost->mRoomSize, 'f', 1).toUtf8().constData();
host.append_attribute("mLineSize") = QString::number(pHost->mLineSize, 'f', 1).toUtf8().constData();
host.append_attribute("mBubbleMode") = pHost->mBubbleMode ? "yes" : "no";
host.append_attribute("mMapViewOnly") = pHost->mMapViewOnly ? "yes" : "no";
host.append_attribute("mShowRoomIDs") = pHost->mShowRoomID ? "yes" : "no";
host.append_attribute("mShowPanel") = pHost->mShowPanel ? "yes" : "no";
host.append_attribute("mHaveMapperScript") = pHost->mHaveMapperScript ? "yes" : "no";
host.append_attribute("mEditorAutoComplete") = pHost->mEditorAutoComplete ? "yes" : "no";
host.append_attribute("mEditorShowBidi") = pHost->getEditorShowBidi() ? "yes" : "no";
host.append_attribute("mAutoWrap") = pHost->autoWrap() ? "yes" : "no";
host.append_attribute("mEditorTheme") = pHost->mEditorTheme.toUtf8().constData();
host.append_attribute("mEditorThemeFile") = pHost->mEditorThemeFile.toUtf8().constData();
host.append_attribute("mThemePreviewItemID") = QString::number(pHost->mThemePreviewItemID).toUtf8().constData();
host.append_attribute("mThemePreviewType") = pHost->mThemePreviewType.toUtf8().constData();
host.append_attribute("mSearchEngineName") = pHost->mSearchEngineName.toUtf8().constData();
host.append_attribute("mTimerSupressionInterval") = pHost->mTimerDebugOutputSuppressionInterval.toString(QLatin1String("HH:mm:ss.zzz")).toUtf8().constData();
host.append_attribute("mUseProxy") = pHost->mUseProxy ? "yes" : "no";
host.append_attribute("mProxyAddress") = pHost->mProxyAddress.toUtf8().constData();
host.append_attribute("mProxyPort") = QString::number(pHost->mProxyPort).toUtf8().constData();
host.append_attribute("mProxyUsername") = pHost->mProxyUsername.toUtf8().constData();
host.append_attribute("mProxyPassword") = pHost->mProxyPassword.toUtf8().constData();
host.append_attribute("mSslTsl") = pHost->mSslTsl ? "yes" : "no";
host.append_attribute("mSslIgnoreExpired") = pHost->mSslIgnoreExpired ? "yes" : "no";
host.append_attribute("mSslIgnoreSelfSigned") = pHost->mSslIgnoreSelfSigned ? "yes" : "no";
host.append_attribute("mSslIgnoreAll") = pHost->mSslIgnoreAll ? "yes" : "no";
host.append_attribute("mDiscordAccessFlags") = QString::number(pHost->mDiscordAccessFlags).toUtf8().constData();
host.append_attribute("mRequiredDiscordUserName") = pHost->mRequiredDiscordUserName.toUtf8().constData();
host.append_attribute("mRequiredDiscordUserDiscriminator") = pHost->mRequiredDiscordUserDiscriminator.toUtf8().constData();
host.append_attribute("mSGRCodeHasColSpaceId") = pHost->getHaveColorSpaceId() ? "yes" : "no";
host.append_attribute("mServerMayRedefineColors") = pHost->getMayRedefineColors() ? "yes" : "no";
quint8 styleCode = 0;
quint8 outerDiameterPercentage = 0;
quint8 innerDiameterPercentage = 0;
QColor outerColor;
QColor innerColor;
pHost->getPlayerRoomStyleDetails(styleCode, outerDiameterPercentage, innerDiameterPercentage, outerColor, innerColor);
host.append_attribute("playerRoomPrimaryColor") = outerColor.name(QColor::HexArgb).toUtf8().constData();
host.append_attribute("playerRoomSecondaryColor") = innerColor.name(QColor::HexArgb).toUtf8().constData();
host.append_attribute("playerRoomStyle") = QString::number(styleCode).toUtf8().constData();
host.append_attribute("playerRoomOuterDiameter") = QString::number(outerDiameterPercentage).toUtf8().constData();
host.append_attribute("playerRoomInnerDiameter") = QString::number(innerDiameterPercentage).toUtf8().constData();
host.append_attribute("CompactInputLine") = pHost->getCompactInputLine() ? "yes" : "no";
QString ignore;
QSetIterator<QChar> it(pHost->mDoubleClickIgnore);
while (it.hasNext()) {
ignore = ignore.append(it.next());
}
host.append_attribute("mDoubleClickIgnore") = ignore.toUtf8().constData();
host.append_attribute("EditorSearchOptions") = QString::number(pHost->mSearchOptions).toUtf8().constData();
host.append_attribute("DebugShowAllProblemCodepoints") = pHost->debugShowAllProblemCodepoints() ? "yes" : "no";
host.append_attribute("announceIncomingText") = pHost->mAnnounceIncomingText ? "yes" : "no";
host.append_attribute("caretShortcut") = QMetaEnum::fromType<Host::CaretShortcut>().valueToKey(
static_cast<int>(pHost->mCaretShortcut));
host.append_attribute("blankLineBehaviour") = QMetaEnum::fromType<Host::BlankLineBehaviour>().valueToKey(
static_cast<int>(pHost->mBlankLineBehaviour));
host.append_attribute("NetworkPacketTimeout") = pHost->mTelnet.getPostingTimeout();
if (int mode = static_cast<int>(pHost->getControlCharacterMode()); mode) {
// Don't bother to include the attribute if it is the default (zero)
// value - and as it is an ASCII digit it only needs
// QString::toLatin1() encoding:
host.append_attribute("ControlCharacterHandling") = QString::number(mode).toLatin1().constData();
}
if (pHost->getLargeAreaExitArrows()) {
host.append_attribute("Large2DMapAreaExitArrows") = "yes";
}
{ // Blocked so that indentation reflects that of the XML file
host.append_child("name").text().set(pHost->mHostName.toUtf8().constData());
auto mInstalledPackages = host.append_child("mInstalledPackages");
for (int i = 0; i < pHost->mInstalledPackages.size(); ++i) {
mInstalledPackages.append_child("string").text().set(pHost->mInstalledPackages.at(i).toUtf8().constData());
}
if (!pHost->mInstalledModules.empty()) {
auto mInstalledModules = host.append_child("mInstalledModules");
QMapIterator<QString, QStringList> it(pHost->mInstalledModules);
pHost->modulesToWrite.clear();
while (it.hasNext()) {
it.next();
mInstalledModules.append_child("key").text().set(it.key().toUtf8().constData());
QStringList entry = it.value();
mInstalledModules.append_child("filepath").text().set(entry.at(0).toUtf8().constData());
if (entry.at(0).endsWith(qsl("mpackage"), Qt::CaseInsensitive) || entry.at(0).endsWith(qsl("zip"), Qt::CaseInsensitive)) {
mInstalledModules.append_child("zipSync").text().set(entry.at(1).toUtf8().constData());
// ensure compatibility with previous versions
mInstalledModules.append_child("globalSave").text().set(0);
} else {
mInstalledModules.append_child("globalSave").text().set(entry.at(1).toUtf8().constData());
}
if (entry.at(1).toInt()) {
pHost->modulesToWrite.insert(it.key(), entry);
}
mInstalledModules.append_child("priority").text().set(QString::number(pHost->mModulePriorities.value(it.key())).toUtf8().constData());
}
}
host.append_child("url").text().set(pHost->mUrl.toUtf8().constData());
host.append_child("serverPackageName").text().set(pHost->mServerGUI_Package_name.toUtf8().constData());
host.append_child("serverPackageVersion").text().set(pHost->mServerGUI_Package_version.toUtf8().constData());
host.append_child("port").text().set(QString::number(pHost->mPort).toUtf8().constData());
host.append_child("borderTopHeight").text().set(QString::number(pHost->mBorderTopHeight).toUtf8().constData());
host.append_child("borderBottomHeight").text().set(QString::number(pHost->mBorderBottomHeight).toUtf8().constData());
host.append_child("borderLeftWidth").text().set(QString::number(pHost->mBorderLeftWidth).toUtf8().constData());
host.append_child("borderRightWidth").text().set(QString::number(pHost->mBorderRightWidth).toUtf8().constData());
host.append_child("wrapAt").text().set(QString::number(pHost->mWrapAt).toUtf8().constData());
host.append_child("wrapIndentCount").text().set(QString::number(pHost->mWrapIndentCount).toUtf8().constData());
host.append_child("mFgColor").text().set(pHost->mFgColor.name().toUtf8().constData());
host.append_child("mBgColor").text().set(pHost->mBgColor.name().toUtf8().constData());
host.append_child("mCommandFgColor").text().set(pHost->mCommandFgColor.name().toUtf8().constData());
host.append_child("mCommandBgColor").text().set(pHost->mCommandBgColor.name().toUtf8().constData());
host.append_child("mCommandLineFgColor").text().set(pHost->mCommandLineFgColor.name().toUtf8().constData());
host.append_child("mCommandLineBgColor").text().set(pHost->mCommandLineBgColor.name().toUtf8().constData());
host.append_child("mBlack").text().set(pHost->mBlack.name().toUtf8().constData());
host.append_child("mLightBlack").text().set(pHost->mLightBlack.name().toUtf8().constData());
host.append_child("mRed").text().set(pHost->mRed.name().toUtf8().constData());
host.append_child("mLightRed").text().set(pHost->mLightRed.name().toUtf8().constData());
host.append_child("mBlue").text().set(pHost->mBlue.name().toUtf8().constData());
host.append_child("mLightBlue").text().set(pHost->mLightBlue.name().toUtf8().constData());
host.append_child("mGreen").text().set(pHost->mGreen.name().toUtf8().constData());
host.append_child("mLightGreen").text().set(pHost->mLightGreen.name().toUtf8().constData());
host.append_child("mYellow").text().set(pHost->mYellow.name().toUtf8().constData());
host.append_child("mLightYellow").text().set(pHost->mLightYellow.name().toUtf8().constData());
host.append_child("mCyan").text().set(pHost->mCyan.name().toUtf8().constData());
host.append_child("mLightCyan").text().set(pHost->mLightCyan.name().toUtf8().constData());
host.append_child("mMagenta").text().set(pHost->mMagenta.name().toUtf8().constData());
host.append_child("mLightMagenta").text().set(pHost->mLightMagenta.name().toUtf8().constData());
host.append_child("mWhite").text().set(pHost->mWhite.name().toUtf8().constData());
host.append_child("mLightWhite").text().set(pHost->mLightWhite.name().toUtf8().constData());
host.append_child("mDisplayFont").text().set(pHost->getDisplayFont().toString().toUtf8().constData());
host.append_child("mCommandLineFont").text().set(pHost->mCommandLineFont.toString().toUtf8().constData());
// There was a mis-spelt duplicate commandSeperator above but it is now gone
host.append_child("mCommandSeparator").text().set(pHost->mCommandSeparator.toUtf8().constData());
host.append_child("commandLineMinimumHeight").text().set(QString::number(pHost->commandLineMinimumHeight).toUtf8().constData());
host.append_child("mFgColor2").text().set(pHost->mFgColor_2.name().toUtf8().constData());
host.append_child("mBgColor2").text().set(pHost->mBgColor_2.name().toUtf8().constData());
host.append_child("mRoomBorderColor").text().set(pHost->mRoomBorderColor.name().toUtf8().constData());
auto mapInfoBgNode = host.append_child("mMapInfoBg");
mapInfoBgNode.text().set(pHost->mMapInfoBg.name().toUtf8().constData());
mapInfoBgNode.append_attribute("alpha").set_value(pHost->mMapInfoBg.alpha());
host.append_child("mBlack2").text().set(pHost->mBlack_2.name().toUtf8().constData());
host.append_child("mLightBlack2").text().set(pHost->mLightBlack_2.name().toUtf8().constData());
host.append_child("mRed2").text().set(pHost->mRed_2.name().toUtf8().constData());
host.append_child("mLightRed2").text().set(pHost->mLightRed_2.name().toUtf8().constData());
host.append_child("mBlue2").text().set(pHost->mBlue_2.name().toUtf8().constData());
host.append_child("mLightBlue2").text().set(pHost->mLightBlue_2.name().toUtf8().constData());
host.append_child("mGreen2").text().set(pHost->mGreen_2.name().toUtf8().constData());
host.append_child("mLightGreen2").text().set(pHost->mLightGreen_2.name().toUtf8().constData());
host.append_child("mYellow2").text().set(pHost->mYellow_2.name().toUtf8().constData());
host.append_child("mLightYellow2").text().set(pHost->mLightYellow_2.name().toUtf8().constData());
host.append_child("mCyan2").text().set(pHost->mCyan_2.name().toUtf8().constData());
host.append_child("mLightCyan2").text().set(pHost->mLightCyan_2.name().toUtf8().constData());
host.append_child("mMagenta2").text().set(pHost->mMagenta_2.name().toUtf8().constData());
host.append_child("mLightMagenta2").text().set(pHost->mLightMagenta_2.name().toUtf8().constData());
host.append_child("mWhite2").text().set(pHost->mWhite_2.name().toUtf8().constData());
host.append_child("mLightWhite2").text().set(pHost->mLightWhite_2.name().toUtf8().constData());
// this crashes
host.append_child("mSpellDic").text().set(pHost->mpConsole->getSystemSpellDictionary().toUtf8().constData());
// TODO: Consider removing these sub-elements that duplicate the same
// attributes - which WERE bugged - when we update the XML format, must leave
// them in place for now even though we no longer use them for compatibility
// with older version of Mudlet
host.append_child("mLineSize").text().set(QString::number(pHost->mLineSize, 'f', 1).toUtf8().constData());
host.append_child("mRoomSize").text().set(QString::number(pHost->mRoomSize, 'f', 1).toUtf8().constData());
}
{
QSetIterator<QString> iterator(pHost->mMapInfoContributors);
while (iterator.hasNext()) {
auto mapInfoContributor = host.append_child("mapInfoContributor");
mapInfoContributor.text().set(iterator.next().toUtf8().constData());
}
}
{
auto iterator = mudlet::self()->mShortcutsManager->iterator();
while (iterator.hasNext()) {
auto key = iterator.next();
auto shortcut = host.append_child("profileShortcut");
shortcut.append_attribute("key") = key.toUtf8().constData();
shortcut.text().set(pHost->profileShortcuts.value(key)->toString().toUtf8().constData());
}
}
{
auto stopwatches = host.append_child("stopwatches");
QListIterator<int> itStopWatchId(pHost->getStopWatchIds());
while (itStopWatchId.hasNext()) {
auto stopWatchId = itStopWatchId.next();
auto pStopWatch = pHost->getStopWatch(stopWatchId);
if (pStopWatch->persistent()) {
auto stopwatch = stopwatches.append_child("stopwatch");
// Three QStrings used here are purely numeric so can be expressed in Latin1 encoding:
stopwatch.append_attribute("id") = QString::number(stopWatchId).toUtf8().constData();
if (pStopWatch->running()) {
stopwatch.append_attribute("running") = "yes";
stopwatch.append_attribute("effectiveStartDateTimeEpochMSecs") = QString::number(QDateTime::currentMSecsSinceEpoch() - pStopWatch->getElapsedMilliSeconds()).toUtf8().constData();
} else {
stopwatch.append_attribute("running") = "no";
stopwatch.append_attribute("elapsedDateTimeMSecs") = QString::number(pStopWatch->getElapsedMilliSeconds()).toUtf8().constData();
}
stopwatch.append_attribute("name") = pStopWatch->name().toUtf8().constData();
}
}
}
writeTriggerPackage(pHost, mudletPackage, true);
writeTimerPackage(pHost, mudletPackage, true);
writeAliasPackage(pHost, mudletPackage, true);
writeActionPackage(pHost, mudletPackage, true);
writeScriptPackage(pHost, mudletPackage, true);
writeKeyPackage(pHost, mudletPackage, true);
writeVariablePackage(pHost, mudletPackage);
}
void XMLexport::writeVariablePackage(Host* pHost, pugi::xml_node& mudletPackage)
{
auto variablePackage = mudletPackage.append_child("VariablePackage");
LuaInterface* lI = pHost->getLuaInterface();
VarUnit* vu = lI->getVarUnit();
//do hidden variables first
{ // Blocked so that indentation reflects that of the XML file
auto hiddenVariables = variablePackage.append_child("HiddenVariables");
QSetIterator<QString> itHiddenVariableName(vu->hiddenByUser);
while (itHiddenVariableName.hasNext()) {
auto variableName = itHiddenVariableName.next();
hiddenVariables.append_child("name").text().set(variableName.toUtf8().constData());
}
}
TVar* base = vu->getBase();
if (!base) {
lI->getVars(false);
base = vu->getBase();
}
if (base) {
QListIterator<TVar*> itVariable(base->getChildren(false));
while (itVariable.hasNext()) {
writeVariable(itVariable.next(), lI, vu, variablePackage);
}
}
}
void XMLexport::writeKeyPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool skipModuleMembers)
{
auto keyPackage = mudletPackage.append_child("KeyPackage");
for (auto it : pHost->mKeyUnit.mKeyRootNodeList) {
if (!it || it->isTemporary() || (skipModuleMembers && it->mModuleMember)) {
continue;
}
writeKey(it, keyPackage);
}
}
void XMLexport::writeScriptPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool skipModuleMembers)
{
auto scriptPackage = mudletPackage.append_child("ScriptPackage");
for (auto it : pHost->mScriptUnit.mScriptRootNodeList) {
if (!it || (skipModuleMembers && it->mModuleMember)) {
continue;
}
writeScript(it, scriptPackage);
}
}
void XMLexport::writeActionPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool skipModuleMembers)
{
auto actionPackage = mudletPackage.append_child("ActionPackage");
for (auto it : pHost->mActionUnit.mActionRootNodeList) {
if (!it || (skipModuleMembers && it->mModuleMember)) {
continue;
}
writeAction(it, actionPackage);
}
}
void XMLexport::writeAliasPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool skipModuleMembers)
{
auto aliasPackage = mudletPackage.append_child("AliasPackage");
for (auto it : pHost->mAliasUnit.mAliasRootNodeList) {
if (!it || (skipModuleMembers && it->mModuleMember)) {
continue;
}
if (!it->isTemporary()) {
writeAlias(it, aliasPackage);
}
}
}
void XMLexport::writeTimerPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool skipModuleMembers)
{
auto timerPackage = mudletPackage.append_child("TimerPackage");
for (auto it : pHost->mTimerUnit.mTimerRootNodeList) {
if (!it || (skipModuleMembers && it->mModuleMember)) {
continue;
}
if (!it->isTemporary()) {
writeTimer(it, timerPackage);
}
}
}
void XMLexport::writeTriggerPackage(const Host* pHost, pugi::xml_node& mudletPackage, bool ignoreModuleMembers)
{
auto triggerPackage = mudletPackage.append_child("TriggerPackage");
for (auto it : pHost->mTriggerUnit.mTriggerRootNodeList) {
if (!it || (ignoreModuleMembers && it->mModuleMember)) {
continue;
}
if (!it->isTemporary()) {
writeTrigger(it, triggerPackage);
}
}
}
void XMLexport::writeVariable(TVar* pVar, LuaInterface* pLuaInterface, VarUnit* pVariableUnit, pugi::xml_node xmlParent)
{
if (pVariableUnit->isSaved(pVar)) {
if (pVar->getValueType() == LUA_TTABLE) {
auto variableGroup = xmlParent.append_child("VariableGroup");
variableGroup.append_child("name").text().set(pVar->getName().toUtf8().constData());
variableGroup.append_child("keyType").text().set(QString::number(pVar->getKeyType()).toUtf8().constData());
variableGroup.append_child("value").text().set(pLuaInterface->getValue(pVar).toUtf8().constData());
variableGroup.append_child("valueType").text().set(QString::number(pVar->getValueType()).toUtf8().constData());
QListIterator<TVar*> itNestedVariable(pVar->getChildren(false));
while (itNestedVariable.hasNext()) {
writeVariable(itNestedVariable.next(), pLuaInterface, pVariableUnit, variableGroup);
}
} else {
auto variable = xmlParent.append_child("Variable");
variable.append_child("name").text().set(pVar->getName().toUtf8().constData());
variable.append_child("keyType").text().set(QString::number(pVar->getKeyType()).toUtf8().constData());
variable.append_child("value").text().set(pLuaInterface->getValue(pVar).toUtf8().constData());
variable.append_child("valueType").text().set(QString::number(pVar->getValueType()).toUtf8().constData());
}
}
}
bool XMLexport::exportProfile(const QString& exportFileName)
{
auto mudletPackage = writeXmlHeader();
if (writeGenericPackage(mpHost, mudletPackage)) {
auto future = QtConcurrent::run(this, &XMLexport::saveXml, exportFileName);
auto watcher = new QFutureWatcher<bool>;
QObject::connect(watcher, &QFutureWatcher<bool>::finished, mpHost, [=]() { mpHost->xmlSaved(qsl("profile")); });
watcher->setFuture(future);
saveFutures.append(future);
return true;
}
return false;
}
bool XMLexport::exportPackage(const QString& exportFileName, bool ignoreModuleMember)
{
auto mudletPackage = writeXmlHeader();
if (writeGenericPackage(mpHost, mudletPackage, ignoreModuleMember)) {
return saveXml(exportFileName);
}
return false;
}
bool XMLexport::writeGenericPackage(Host* pHost, pugi::xml_node& mudletPackage, bool ignoreModuleMember)
{
writeTriggerPackage(pHost, mudletPackage, ignoreModuleMember);
writeTimerPackage(pHost, mudletPackage, ignoreModuleMember);
writeAliasPackage(pHost, mudletPackage, ignoreModuleMember);
writeActionPackage(pHost, mudletPackage, ignoreModuleMember);
writeScriptPackage(pHost, mudletPackage, ignoreModuleMember);
writeKeyPackage(pHost, mudletPackage, ignoreModuleMember);
// variables weren't previously exported as a generic package
writeVariablePackage(pHost, mudletPackage);
return true;
}
pugi::xml_node XMLexport::writeXmlHeader()
{
auto decl = mExportDoc.prepend_child(pugi::node_declaration);
decl.append_attribute("version") = "1.0";
decl.append_attribute("encoding") = "UTF-8";
mExportDoc.append_child(pugi::node_doctype).set_value("MudletPackage");
auto mudletPackage = mExportDoc.append_child("MudletPackage");
mudletPackage.append_attribute("version") = mudlet::self()->scmMudletXmlDefaultVersion.toUtf8().constData();
return mudletPackage;
}
bool XMLexport::exportTrigger(const QString& fileName)
{
auto mudletPackage = writeXmlHeader();
auto triggerPackage = mudletPackage.append_child("TriggerPackage");
writeTrigger(mpTrigger, triggerPackage);
return saveXml(fileName);
}
void XMLexport::exportToClipboard(TTrigger* pT)
{
// The use of pT is a cludge - it was already used in the previously invoked
// in this XMLexport instance's constructor (and stored in mpTrigger) and it
// is only used here for its signature.
Q_UNUSED(pT);
auto mudletPackage = writeXmlHeader();
auto triggerPackage = mudletPackage.append_child("TriggerPackage");
writeTrigger(mpTrigger, triggerPackage);
auto xml = saveXml();
auto clipboard = QApplication::clipboard();
clipboard->setText(xml, QClipboard::Clipboard);
}
void XMLexport::writeTrigger(TTrigger* pT, pugi::xml_node xmlParent)
{
if (!pT->mModuleMasterFolder && pT->exportItem) {
auto trigger = xmlParent.append_child(pT->isFolder() ? "TriggerGroup" : "Trigger");
// set the xml parent to the trigger we just made so nested triggers will get written to it
xmlParent = trigger;
trigger.append_attribute("isActive") = pT->shouldBeActive() ? "yes" : "no";
trigger.append_attribute("isFolder") = pT->isFolder() ? "yes" : "no";
trigger.append_attribute("isTempTrigger") = pT->isTemporary() ? "yes" : "no";
trigger.append_attribute("isMultiline") = pT->mIsMultiline ? "yes" : "no";
trigger.append_attribute("isPerlSlashGOption") = pT->mPerlSlashGOption ? "yes" : "no";
trigger.append_attribute("isColorizerTrigger") = pT->mIsColorizerTrigger ? "yes" : "no";
trigger.append_attribute("isFilterTrigger") = pT->mFilterTrigger ? "yes" : "no";
trigger.append_attribute("isSoundTrigger") = pT->mSoundTrigger ? "yes" : "no";
trigger.append_attribute("isColorTrigger") = pT->mColorTrigger ? "yes" : "no";
trigger.append_attribute("isColorTriggerFg") = (pT->mColorTriggerFgAnsi != TTrigger::scmIgnored) ? "yes" : "no";
trigger.append_attribute("isColorTriggerBg") = (pT->mColorTriggerBgAnsi != TTrigger::scmIgnored) ? "yes" : "no";
{ // Blocked so that indentation reflects that of the XML file
trigger.append_child("name").text().set(pT->mName.toUtf8().constData());
writeScriptElement(pT->mScript, trigger);
trigger.append_child("triggerType").text().set(QString::number(pT->mTriggerType).toUtf8().constData());
trigger.append_child("conditonLineDelta").text().set(QString::number(pT->mConditionLineDelta).toUtf8().constData());
trigger.append_child("mStayOpen").text().set(QString::number(pT->mStayOpen).toUtf8().constData());
trigger.append_child("mCommand").text().set(pT->mCommand.toUtf8().constData());
trigger.append_child("packageName").text().set(pT->mPackageName.toUtf8().constData());
trigger.append_child("mFgColor").text().set(pT->mFgColor == QColorConstants::Transparent ? "transparent": pT->mFgColor.name().toUtf8().constData());
trigger.append_child("mBgColor").text().set(pT->mBgColor == QColorConstants::Transparent ? "transparent": pT->mBgColor.name().toUtf8().constData());
trigger.append_child("mSoundFile").text().set(pT->mSoundFile.toUtf8().constData());
trigger.append_child("colorTriggerFgColor").text().set(pT->mColorTriggerFgColor.name().toUtf8().constData());
trigger.append_child("colorTriggerBgColor").text().set(pT->mColorTriggerBgColor.name().toUtf8().constData());
auto regexCodeList = trigger.append_child("regexCodeList");
// Revert the first 16 ANSI colour codes back to the wrong values
// that are still used in the save files
QStringList unfixedAnsiColourPatternList = remapAnsiToColorNumber(pT->mPatterns, pT->mPatternKinds);
for (int i = 0; i < unfixedAnsiColourPatternList.size(); ++i) {
regexCodeList.append_child("string").text().set(unfixedAnsiColourPatternList.at(i).toUtf8().constData());
}
auto regexCodePropertyList = trigger.append_child("regexCodePropertyList");
for (int i : qAsConst(pT->mPatternKinds)) {
regexCodePropertyList.append_child("integer").text().set(QString::number(i).toUtf8().constData());
}
}
}
for (auto& it : *pT->mpMyChildrenList) {
writeTrigger(it, xmlParent);
}
}
bool XMLexport::exportAlias(const QString& fileName)
{
auto mudletPackage = writeXmlHeader();
auto aliasPackage = mudletPackage.append_child("AliasPackage");
writeAlias(mpAlias, aliasPackage);
return saveXml(fileName);
}
void XMLexport::exportToClipboard(TAlias* pT)
{
// The use of pT is a cludge - it was already used in the previously invoked
// in this XMLexport instance's constructor (and stored in mpAlias) and it
// is only used here for its signature.
Q_UNUSED(pT);
auto mudletPackage = writeXmlHeader();
auto aliasPackage = mudletPackage.append_child("AliasPackage");
writeAlias(mpAlias, aliasPackage);
auto xml = saveXml();
auto clipboard = QApplication::clipboard();
clipboard->setText(xml, QClipboard::Clipboard);
}
void XMLexport::writeAlias(TAlias* pT, pugi::xml_node xmlParent)
{
if (!pT->mModuleMasterFolder && pT->exportItem) {
auto aliasContents = xmlParent.append_child(pT->isFolder() ? "AliasGroup" : "Alias");
// set the xml parent to the trigger we just made so nested triggers will get written to it
xmlParent = aliasContents;
aliasContents.append_attribute("isActive") = pT->shouldBeActive() ? "yes" : "no";
aliasContents.append_attribute("isFolder") = pT->isFolder() ? "yes" : "no";
{ // Blocked so that indentation reflects that of the XML file
aliasContents.append_child("name").text().set(pT->mName.toUtf8().constData());
writeScriptElement(pT->mScript, aliasContents);
aliasContents.append_child("command").text().set(pT->mCommand.toUtf8().constData());
aliasContents.append_child("packageName").text().set(pT->mPackageName.toUtf8().constData());
aliasContents.append_child("regex").text().set(pT->mRegexCode.toUtf8().constData());
}
}
for (auto& it : *pT->mpMyChildrenList) {
writeAlias(it, xmlParent);
}
}
bool XMLexport::exportAction(const QString& fileName)
{
auto mudletPackage = writeXmlHeader();
auto actionPackage = mudletPackage.append_child("ActionPackage");
writeAction(mpAction, actionPackage);
return saveXml(fileName);
}
void XMLexport::exportToClipboard(TAction* pT)
{
// The use of pT is a cludge - it was already used in the previously invoked
// in this XMLexport instance's constructor (and stored in mpAction) and it
// is only used here for its signature.
Q_UNUSED(pT);
auto mudletPackage = writeXmlHeader();
auto actionPackage = mudletPackage.append_child("ActionPackage");
writeAction(mpAction, actionPackage);
auto xml = saveXml();
auto clipboard = QApplication::clipboard();
clipboard->setText(xml, QClipboard::Clipboard);
}
void XMLexport::writeAction(TAction* pT, pugi::xml_node xmlParent)
{
if (!pT->mModuleMasterFolder && pT->exportItem) {
auto actionContents = xmlParent.append_child(pT->isFolder() ? "ActionGroup" : "Action");
// set the xml parent to the trigger we just made so nested triggers will get written to it
xmlParent = actionContents;
actionContents.append_attribute("isActive") = pT->shouldBeActive() ? "yes" : "no";
actionContents.append_attribute("isFolder") = pT->isFolder() ? "yes" : "no";
actionContents.append_attribute("isPushButton") = pT->mIsPushDownButton ? "yes" : "no";
actionContents.append_attribute("isFlatButton") = pT->mButtonFlat ? "yes" : "no";
actionContents.append_attribute("useCustomLayout") = pT->mUseCustomLayout ? "yes" : "no";
{ // Blocked so that indentation reflects that of the XML file
actionContents.append_child("name").text().set(pT->mName.toUtf8().constData());
actionContents.append_child("packageName").text().set(pT->mPackageName.toUtf8().constData());
writeScriptElement(pT->mScript, actionContents);
actionContents.append_child("css").text().set(pT->css.toUtf8().constData());