summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/AddonDatabase.h
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/addons/AddonDatabase.h')
-rw-r--r--xbmc/addons/AddonDatabase.h175
1 files changed, 175 insertions, 0 deletions
diff --git a/xbmc/addons/AddonDatabase.h b/xbmc/addons/AddonDatabase.h
new file mode 100644
index 0000000..b32f2a4
--- /dev/null
+++ b/xbmc/addons/AddonDatabase.h
@@ -0,0 +1,175 @@
1#pragma once
2/*
3 * Copyright (C) 2005-2013 Team XBMC
4 * http://xbmc.org
5 *
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "dbwrappers/Database.h"
23#include "addons/Addon.h"
24#include "FileItem.h"
25#include <string>
26
27class CAddonDatabase : public CDatabase
28{
29public:
30 CAddonDatabase();
31 virtual ~CAddonDatabase();
32 virtual bool Open();
33
34 int AddAddon(const ADDON::AddonPtr& item, int idRepo);
35 bool GetAddon(const std::string& addonID, ADDON::AddonPtr& addon);
36 bool GetAddons(ADDON::VECADDONS& addons);
37
38 /*! \brief grab the (largest) add-on version for an add-on */
39 ADDON::AddonVersion GetAddonVersion(const std::string &id);
40
41 /*! \brief Grab the repository from which a given addon came
42 \param addonID - the id of the addon in question
43 \param repo [out] - the id of the repository
44 \return true if a repo was found, false otherwise.
45 */
46 bool GetRepoForAddon(const std::string& addonID, std::string& repo);
47 int AddRepository(const std::string& id, const ADDON::VECADDONS& addons, const std::string& checksum, const ADDON::AddonVersion& version);
48 void DeleteRepository(const std::string& id);
49 void DeleteRepository(int id);
50 int GetRepoChecksum(const std::string& id, std::string& checksum);
51 bool GetRepository(const std::string& id, ADDON::VECADDONS& addons);
52 bool GetRepository(int id, ADDON::VECADDONS& addons);
53 bool SetRepoTimestamp(const std::string& id, const std::string& timestamp, const ADDON::AddonVersion& version);
54
55 /*! \brief Retrieve the time a repository was last checked
56 \param id id of the repo
57 \return last time the repo was checked, current time if not available
58 \sa SetRepoTimestamp */
59 CDateTime GetRepoTimestamp(const std::string& id);
60
61 ADDON::AddonVersion GetRepoVersion(const std::string& id);
62
63 bool Search(const std::string& search, ADDON::VECADDONS& items);
64 static void SetPropertiesFromAddon(const ADDON::AddonPtr& addon, CFileItemPtr& item);
65
66 /*! \brief Disable an addon.
67 Sets a flag that this addon has been disabled. If disabled, it is usually still available on disk.
68 \param addonID id of the addon to disable
69 \param disable whether to enable or disable. Defaults to true (disable)
70 \return true on success, false on failure
71 \sa IsAddonDisabled, HasDisabledAddons */
72 bool DisableAddon(const std::string &addonID, bool disable = true);
73
74 /*! \brief Checks if an addon is in the database.
75 \param addonID id of the addon to be checked
76 \return true if addon is in database, false if addon is not in database yet */
77 bool HasAddon(const std::string &addonID);
78
79 /*! \brief Check whether an addon has been disabled via DisableAddon.
80 \param addonID id of the addon to check
81 \return true if the addon is disabled, false otherwise
82 \sa DisableAddon, HasDisabledAddons */
83 bool IsAddonDisabled(const std::string &addonID);
84
85 /*! \brief Check whether we have disabled addons.
86 \return true if we have disabled addons, false otherwise
87 \sa DisableAddon, IsAddonDisabled */
88 bool HasDisabledAddons();
89
90 /*! @deprecated only here to allow clean upgrades from earlier pvr versions
91 */
92 bool IsSystemPVRAddonEnabled(const std::string &addonID);
93
94 /*! \brief Mark an addon as broken
95 Sets a flag that this addon has been marked as broken in the repository.
96 \param addonID id of the addon to mark as broken
97 \param reason why it is broken - if non empty we take it as broken. Defaults to empty
98 \return true on success, false on failure
99 \sa IsAddonBroken */
100 bool BreakAddon(const std::string &addonID, const std::string& reason="");
101
102 /*! \brief Check whether an addon has been marked as broken via BreakAddon.
103 \param addonID id of the addon to check
104 \return reason if the addon is broken, blank otherwise
105 \sa BreakAddon */
106 std::string IsAddonBroken(const std::string &addonID);
107
108 bool BlacklistAddon(const std::string& addonID, const std::string& version);
109 bool IsAddonBlacklisted(const std::string& addonID, const std::string& version);
110 bool RemoveAddonFromBlacklist(const std::string& addonID,
111 const std::string& version);
112
113 /*! \brief Store an addon's package filename and that file's hash for future verification
114 \param addonID id of the addon we're adding a package for
115 \param packageFileName filename of the package
116 \param hash MD5 checksum of the package
117 \return Whether or not the info successfully made it into the DB.
118 \sa GetPackageHash, RemovePackage
119 */
120 bool AddPackage(const std::string& addonID,
121 const std::string& packageFileName,
122 const std::string& hash);
123 /*! \brief Query the MD5 checksum of the given given addon's given package
124 \param addonID id of the addon we're who's package we're querying
125 \param packageFileName filename of the package
126 \param hash return the MD5 checksum of the package
127 \return Whether or not we found a hash for the given addon's given package
128 \sa AddPackage, RemovePackage
129 */
130 bool GetPackageHash(const std::string& addonID,
131 const std::string& packageFileName,
132 std::string& hash);
133 /*! \brief Remove a package's info from the database
134 \param packageFileName filename of the package
135 \return Whether or not we succeeded in removing the package
136 \sa AddPackage, GetPackageHash
137 */
138 bool RemovePackage(const std::string& packageFileName);
139protected:
140 virtual void CreateTables();
141 virtual void CreateAnalytics();
142 virtual void UpdateTables(int version);
143 virtual int GetMinSchemaVersion() const { return 15; }
144 virtual int GetSchemaVersion() const { return 17; }
145 const char *GetBaseDBName() const { return "Addons"; }
146
147 bool GetAddon(int id, ADDON::AddonPtr& addon);
148
149 /* keep in sync with the select in GetAddon */
150 enum _AddonFields
151 {
152 addon_id=0,
153 addon_type,
154 addon_name,
155 addon_summary,
156 addon_description,
157 addon_stars,
158 addon_path,
159 addon_addonID,
160 addon_icon,
161 addon_version,
162 addon_changelog,
163 addon_fanart,
164 addon_author,
165 addon_disclaimer,
166 addon_minversion,
167 broken_reason,
168 addonextra_key,
169 addonextra_value,
170 dependencies_addon,
171 dependencies_version,
172 dependencies_optional
173 } AddonFields;
174};
175