1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "guilib/guiinfo/AddonsGUIInfo.h"
#include "FileItem.h"
#include "ServiceBroker.h"
#include "addons/Addon.h"
#include "addons/AddonManager.h"
#include "addons/addoninfo/AddonInfo.h"
#include "guilib/LocalizeStrings.h"
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
#include "utils/StringUtils.h"
using namespace KODI::GUILIB::GUIINFO;
bool CAddonsGUIInfo::InitCurrentItem(CFileItem *item)
{
return false;
}
bool CAddonsGUIInfo::GetLabel(std::string& value, const CFileItem *item, int contextWindow, const CGUIInfo &info, std::string *fallback) const
{
const std::shared_ptr<const ADDON::IAddon> addonInfo = item->GetAddonInfo();
if (addonInfo)
{
switch (info.m_info)
{
///////////////////////////////////////////////////////////////////////////////////////////////
// LISTITEM_*
///////////////////////////////////////////////////////////////////////////////////////////////
case LISTITEM_ADDON_NAME:
value = addonInfo->Name();
return true;
case LISTITEM_ADDON_VERSION:
value = addonInfo->Version().asString();
return true;
case LISTITEM_ADDON_CREATOR:
value = addonInfo->Author();
return true;
case LISTITEM_ADDON_SUMMARY:
value = addonInfo->Summary();
return true;
case LISTITEM_ADDON_DESCRIPTION:
value = addonInfo->Description();
return true;
case LISTITEM_ADDON_DISCLAIMER:
value = addonInfo->Disclaimer();
return true;
case LISTITEM_ADDON_NEWS:
value = addonInfo->ChangeLog();
return true;
case LISTITEM_ADDON_BROKEN:
{
// Fallback for old GUI info
if (addonInfo->LifecycleState() == ADDON::AddonLifecycleState::BROKEN)
value = addonInfo->LifecycleStateDescription();
else
value = "";
return true;
}
case LISTITEM_ADDON_LIFECYCLE_TYPE:
{
const ADDON::AddonLifecycleState state = addonInfo->LifecycleState();
switch (state)
{
case ADDON::AddonLifecycleState::BROKEN:
value = g_localizeStrings.Get(24171); // "Broken"
break;
case ADDON::AddonLifecycleState::DEPRECATED:
value = g_localizeStrings.Get(24170); // "Deprecated";
break;
case ADDON::AddonLifecycleState::NORMAL:
default:
value = g_localizeStrings.Get(24169); // "Normal";
break;
}
return true;
}
case LISTITEM_ADDON_LIFECYCLE_DESC:
value = addonInfo->LifecycleStateDescription();
return true;
case LISTITEM_ADDON_TYPE:
value = ADDON::CAddonInfo::TranslateType(addonInfo->Type(), true);
return true;
case LISTITEM_ADDON_INSTALL_DATE:
value = addonInfo->InstallDate().GetAsLocalizedDateTime();
return true;
case LISTITEM_ADDON_LAST_UPDATED:
if (addonInfo->LastUpdated().IsValid())
{
value = addonInfo->LastUpdated().GetAsLocalizedDateTime();
return true;
}
break;
case LISTITEM_ADDON_LAST_USED:
if (addonInfo->LastUsed().IsValid())
{
value = addonInfo->LastUsed().GetAsLocalizedDateTime();
return true;
}
break;
case LISTITEM_ADDON_ORIGIN:
{
if (item->GetAddonInfo()->Origin() == ADDON::ORIGIN_SYSTEM)
{
value = g_localizeStrings.Get(24992);
return true;
}
if (!item->GetAddonInfo()->OriginName().empty())
{
value = item->GetAddonInfo()->OriginName();
return true;
}
else if (!item->GetAddonInfo()->Origin().empty())
{
value = item->GetAddonInfo()->Origin();
return true;
}
value = g_localizeStrings.Get(25014);
return true;
}
case LISTITEM_ADDON_SIZE:
{
uint64_t packageSize = item->GetAddonInfo()->PackageSize();
if (packageSize > 0)
{
value = StringUtils::FormatFileSize(packageSize);
return true;
}
break;
}
}
}
switch (info.m_info)
{
///////////////////////////////////////////////////////////////////////////////////////////////
// ADDON_*
///////////////////////////////////////////////////////////////////////////////////////////////
case ADDON_SETTING_STRING:
{
ADDON::AddonPtr addon;
if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon,
ADDON::OnlyEnabled::CHOICE_YES))
{
return false;
}
value = addon->GetSetting(info.GetData5());
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////
// SYSTEM_*
///////////////////////////////////////////////////////////////////////////////////////////////
case SYSTEM_ADDON_TITLE:
case SYSTEM_ADDON_ICON:
case SYSTEM_ADDON_VERSION:
{
// This logic does not check/care whether an addon has been disabled/marked as broken,
// it simply retrieves it's name or icon that means if an addon is placed on the home screen it
// will stay there even if it's disabled/marked as broken. This might need to be changed/fixed
// in the future.
ADDON::AddonPtr addon;
if (!info.GetData3().empty())
{
bool success = CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon,
ADDON::OnlyEnabled::CHOICE_YES);
if (!success || !addon)
break;
if (info.m_info == SYSTEM_ADDON_TITLE)
{
value = addon->Name();
return true;
}
if (info.m_info == SYSTEM_ADDON_ICON)
{
value = addon->Icon();
return true;
}
if (info.m_info == SYSTEM_ADDON_VERSION)
{
value = addon->Version().asString();
return true;
}
}
break;
}
}
return false;
}
bool CAddonsGUIInfo::GetInt(int& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
{
switch (info.m_info)
{
///////////////////////////////////////////////////////////////////////////////////////////////
// ADDON_*
///////////////////////////////////////////////////////////////////////////////////////////////
case ADDON_SETTING_INT:
{
ADDON::AddonPtr addon;
if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon,
ADDON::OnlyEnabled::CHOICE_YES))
{
return false;
}
return addon->GetSettingInt(info.GetData5(), value);
}
}
return false;
}
bool CAddonsGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int contextWindow, const CGUIInfo &info) const
{
switch (info.m_info)
{
///////////////////////////////////////////////////////////////////////////////////////////////
// ADDON_*
///////////////////////////////////////////////////////////////////////////////////////////////
case ADDON_SETTING_BOOL:
{
ADDON::AddonPtr addon;
if (!CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon,
ADDON::OnlyEnabled::CHOICE_YES))
{
return false;
}
return addon->GetSettingBool(info.GetData5(), value);
}
///////////////////////////////////////////////////////////////////////////////////////////////
// SYSTEM_*
///////////////////////////////////////////////////////////////////////////////////////////////
case SYSTEM_HAS_ADDON:
{
ADDON::AddonPtr addon;
value = CServiceBroker::GetAddonMgr().IsAddonInstalled(info.GetData3());
return true;
}
case SYSTEM_ADDON_IS_ENABLED:
{
value = false;
ADDON::AddonPtr addon;
if (CServiceBroker::GetAddonMgr().GetAddon(info.GetData3(), addon,
ADDON::OnlyEnabled::CHOICE_YES))
value = !CServiceBroker::GetAddonMgr().IsAddonDisabled(info.GetData3());
return true;
}
case LISTITEM_ISAUTOUPDATEABLE:
{
value = true;
const CFileItem* item = static_cast<const CFileItem*>(gitem);
if (item->GetAddonInfo())
value = CServiceBroker::GetAddonMgr().IsAutoUpdateable(item->GetAddonInfo()->ID()) ||
!CServiceBroker::GetAddonMgr().IsAddonInstalled(item->GetAddonInfo()->ID(),
item->GetAddonInfo()->Origin());
//! @Todo: store origin of not-autoupdateable installed addons in table 'update_rules'
// of the addon database. this is needed to pin ambiguous addon-id's that are
// available from multiple origins accordingly.
//
// after this is done the above call should be changed to
//
// value = CServiceBroker::GetAddonMgr().IsAutoUpdateable(item->GetAddonInfo()->ID(),
// item->GetAddonInfo()->Origin());
return true;
}
}
return false;
}
|