1 // Copyright (C) 2013 James Turner - zakalawe@mac.com
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.
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.
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.
18 #ifndef SG_PACKAGE_PACKAGE_HXX
19 #define SG_PACKAGE_PACKAGE_HXX
24 #include <simgear/props/props.hxx>
25 #include <simgear/misc/strutils.hxx>
27 #include <simgear/structure/function_list.hxx>
28 #include <simgear/structure/SGReferenced.hxx>
29 #include <simgear/structure/SGSharedPtr.hxx>
31 typedef std::set<std::string> string_set;
44 typedef SGSharedPtr<Package> PackageRef;
45 typedef SGSharedPtr<Catalog> CatalogRef;
46 typedef SGSharedPtr<Install> InstallRef;
48 typedef std::vector<PackageRef> PackageList;
50 class Package : public SGReferenced
54 typedef boost::function<void(Package*, Install*)> InstallCallback;
57 * get or create an install for the package
62 existingInstall(const InstallCallback& cb = InstallCallback()) const;
64 bool isInstalled() const;
66 std::string id() const;
69 * Variant IDs. Note the primary ID will always be included as
70 * variants()[0], to simplify enumerating all variants
72 string_list variants() const;
75 * Fully-qualified ID, including our catalog'd ID
77 std::string qualifiedId() const;
80 * Fully-qualified ID, including our catalog'd ID
82 std::string qualifiedVariantId(const unsigned int variantIndex) const;
85 * human-readable name - note this is probably not localised,
86 * although this is not ruled out for the future.
88 std::string name() const;
91 * Human readable name of a variant
93 std::string nameForVariant(const std::string& vid) const;
95 std::string nameForVariant(const unsigned int vIndex) const;
98 * syntactic sugar to get the localised description
100 std::string description() const;
103 * access the raw property data in the package
105 SGPropertyNode* properties() const;
108 * hex-encoded MD5 sum of the download files
110 std::string md5() const;
112 std::string getLocalisedProp(const std::string& aName) const;
114 unsigned int revision() const;
116 size_t fileSizeBytes() const;
118 CatalogRef catalog() const
119 { return m_catalog; }
121 bool matches(const SGPropertyNode* aFilter) const;
123 string_set tags() const;
126 * download URLs for the package
128 string_list downloadUrls() const;
130 string_list thumbnailUrls() const;
133 * thumbnail file paths within the package on disk
135 string_list thumbnails() const;
138 * Packages we depend upon.
139 * If the dependency list cannot be satisifed for some reason,
140 * this will raise an sg_exception.
142 PackageList dependencies() const;
145 * Name of the package directory on disk. This may or may not be the
146 * same as the primary ID, depending on the aircraft author
148 std::string dirName() const;
150 SGPath pathOnDisk() const;
152 friend class Catalog;
155 Package(const SGPropertyNode* aProps, CatalogRef aCatalog);
157 void initWithProps(const SGPropertyNode* aProps);
159 void updateFromProps(const SGPropertyNode* aProps);
161 std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
163 SGPropertyNode_ptr m_props;
166 CatalogRef m_catalog;
168 mutable function_list<InstallCallback> _install_cb;
174 } // of namespace pkg
176 } // of namespace simgear
178 #endif // of SG_PACKAGE_PACKAGE_HXX