source: filezilla/trunk/fuentes/src/interface/xmlfunctions.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

File size: 3.5 KB
Line 
1/*
2 * xmlfunctions.h declares some useful xml helper functions, especially to
3 * improve usability together with wxWidgets.
4 */
5
6#ifndef __XMLFUNCTIONS_H__
7#define __XMLFUNCTIONS_H__
8
9#ifdef HAVE_LIBPUGIXML
10#include <pugixml.hpp>
11#else
12#include "../pugixml/pugixml.hpp"
13#endif
14
15class CXmlFile final
16{
17public:
18        CXmlFile() = default;
19        explicit CXmlFile(const wxString& fileName, wxString const& root = wxString());
20
21        ~CXmlFile();
22
23        CXmlFile(CXmlFile const&) = delete;
24        CXmlFile& operator=(CXmlFile const&) = delete;
25
26        pugi::xml_node CreateEmpty();
27
28        wxString GetFileName() const { return m_fileName; }
29        void SetFileName(const wxString& name);
30
31        bool HasFileName() const { return !m_fileName.empty(); }
32
33        // Sets error description on failure
34        pugi::xml_node Load();
35
36        wxString GetError() const { return m_error; }
37        size_t GetRawDataLength();
38        void GetRawDataHere(char* p, size_t size); // p has to big enough to hold at least GetRawDataLength() bytes
39
40        bool ParseData(char* data); // data has to be 0-terminated
41
42        void Close();
43
44        pugi::xml_node GetElement() { return m_element; }
45        pugi::xml_node const GetElement() const { return m_element; }
46
47        bool Modified();
48
49        bool Save(bool printError);
50
51        bool IsFromFutureVersion() const;
52protected:
53        wxString GetRedirectedName() const;
54
55        // Opens the specified XML file if it exists or creates a new one otherwise.
56        // Returns 0 on error.
57        bool GetXmlFile(wxString const& file);
58
59        // Sets version and platform in root element
60        void UpdateMetadata();
61
62        // Save the XML document to the given file
63        bool SaveXmlFile();
64
65        fz::datetime m_modificationTime;
66        wxString m_fileName;
67        pugi::xml_document m_document;
68        pugi::xml_node m_element;
69
70        wxString m_error;
71
72        wxString m_rootName{_T("FileZilla3")};
73};
74
75// Convert the given utf-8 string into wxString
76wxString ConvLocal(const char *value);
77
78void SetTextAttribute(pugi::xml_node node, const char* name, const wxString& value);
79wxString GetTextAttribute(pugi::xml_node node, const char* name);
80
81int GetAttributeInt(pugi::xml_node node, const char* name);
82void SetAttributeInt(pugi::xml_node node, const char* name, int value);
83
84pugi::xml_node FindElementWithAttribute(pugi::xml_node node, const char* element, const char* attribute, const char* value);
85
86// Add a new child element with the specified name and value to the xml document
87pugi::xml_node AddTextElement(pugi::xml_node node, const char* name, const wxString& value, bool overwrite = false);
88void AddTextElement(pugi::xml_node node, const char* name, int64_t value, bool overwrite = false);
89pugi::xml_node AddTextElementRaw(pugi::xml_node node, const char* name, const char* value, bool overwrite = false);
90
91// Set the current element's text value
92void AddTextElement(pugi::xml_node node, const wxString& value);
93void AddTextElement(pugi::xml_node node, int64_t value);
94void AddTextElementRaw(pugi::xml_node node, const char* value);
95
96// Get string from named child element
97wxString GetTextElement(pugi::xml_node node, const char* name);
98wxString GetTextElement_Trimmed(pugi::xml_node node, const char* name);
99
100// Get string from current element
101wxString GetTextElement(pugi::xml_node node);
102wxString GetTextElement_Trimmed(pugi::xml_node node);
103
104// Get (64-bit) integer from named element
105int64_t GetTextElementInt(pugi::xml_node node, const char* name, int defValue = 0);
106
107bool GetTextElementBool(pugi::xml_node node, const char* name, bool defValue = false);
108
109// Functions to save and retrieve CServer objects to the XML file
110void SetServer(pugi::xml_node node, const CServer& server);
111bool GetServer(pugi::xml_node node, CServer& server);
112
113#endif //__XMLFUNCTIONS_H__
Note: See TracBrowser for help on using the repository browser.