]> git.mxchange.org Git - simgear.git/blob - simgear/package/Package.hxx
Package support progress
[simgear.git] / simgear / package / Package.hxx
1 // Copyright (C) 2013  James Turner - zakalawe@mac.com
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifndef SG_PACKAGE_PACKAGE_HXX
19 #define SG_PACKAGE_PACKAGE_HXX
20
21 #include <set>
22 #include <vector>
23
24 #include <simgear/props/props.hxx>
25 #include <simgear/misc/strutils.hxx>
26
27 #include <simgear/structure/function_list.hxx>
28 #include <simgear/structure/SGReferenced.hxx>
29 #include <simgear/structure/SGSharedPtr.hxx>
30
31 typedef std::set<std::string> string_set;
32
33 namespace simgear
34 {
35     
36 namespace pkg
37 {
38
39 // forward decls
40 class Install;
41 class Catalog;
42 class Package;
43   
44 typedef SGSharedPtr<Package> PackageRef;
45 typedef SGSharedPtr<Catalog> CatalogRef;
46 typedef SGSharedPtr<Install> InstallRef;
47
48 typedef std::vector<PackageRef> PackageList;
49     
50   class Package : public SGReferenced
51 {
52 public:
53
54     typedef boost::function<void(Package*, Install*)> InstallCallback;
55
56     /**
57      * get or create an install for the package
58      */
59     InstallRef install();
60
61     InstallRef
62     existingInstall(const InstallCallback& cb = InstallCallback()) const;
63
64     bool isInstalled() const;
65     
66     std::string id() const;
67
68     /**
69      * Variant IDs. Note the primary ID will always be included as 
70      * variants()[0], to simplify enumerating all variants
71      */
72     string_list variants() const;
73
74     /**
75      * Fully-qualified ID, including our catalog'd ID
76      */
77     std::string qualifiedId() const;
78     
79     /**
80      * human-readable name - note this is probably not localised,
81      * although this is not ruled out for the future.
82      */
83     std::string name() const;
84
85     /**
86      * Human readable name of a variant
87      */
88     std::string nameForVariant(const std::string& vid) const;
89
90     /**
91      * syntactic sugar to get the localised description
92      */
93     std::string description() const;
94     
95     /**
96      * access the raw property data in the package
97      */
98     SGPropertyNode* properties() const;
99     
100     /**
101      * hex-encoded MD5 sum of the download files
102      */
103     std::string md5() const;
104     
105     std::string getLocalisedProp(const std::string& aName) const;
106
107     unsigned int revision() const;
108   
109     size_t fileSizeBytes() const;
110   
111     CatalogRef catalog() const
112         { return m_catalog; }
113     
114     bool matches(const SGPropertyNode* aFilter) const;
115
116     string_set tags() const;
117
118     /**
119      * download URLs for the package
120      */
121     string_list downloadUrls() const;
122     
123     string_list thumbnailUrls() const;
124     
125     /**
126      * thumbnail file paths within the package on disk
127      */
128     string_list thumbnails() const;
129     
130     /**
131      * Packages we depend upon.
132      * If the dependency list cannot be satisifed for some reason,
133      * this will raise an sg_exception.
134      */
135     PackageList dependencies() const;
136
137     /**
138      * Name of the package directory on disk. This may or may not be the
139      * same as the primary ID, depending on the aircraft author
140      */
141     std::string dirName() const;
142 private:
143     SGPath pathOnDisk() const;
144
145     friend class Catalog;
146     friend class Root;
147     
148     Package(const SGPropertyNode* aProps, CatalogRef aCatalog);
149     
150     void initWithProps(const SGPropertyNode* aProps);
151
152     void updateFromProps(const SGPropertyNode* aProps);
153
154     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
155     
156     SGPropertyNode_ptr m_props;
157     std::string m_id;
158     string_set m_tags;
159     CatalogRef m_catalog;
160
161     mutable function_list<InstallCallback> _install_cb;
162 };
163
164
165
166
167 } // of namespace pkg
168
169 } // of namespace simgear
170
171 #endif // of SG_PACKAGE_PACKAGE_HXX
172