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

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

First release to xenial

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