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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "GUIDialogAddonInfo.h"
#include "GUIDialogYesNo.h"
#include "addons/AddonManager.h"
#include "AddonDatabase.h"
#include "FileItem.h"
#include "FileSystem/File.h"
#include "FileSystem/SpecialProtocol.h"
#include "GUIDialogAddonSettings.h"
#include "GUIDialogTextViewer.h"
#include "GUIUserMessages.h"
#include "GUIWindowAddonBrowser.h"
#include "GUIWindowManager.h"
#include "URL.h"
#include "utils/JobManager.h"
#include "utils/FileOperationJob.h"
#define CONTROL_BTN_INSTALL 6
#define CONTROL_BTN_ENABLE 7
#define CONTROL_BTN_UPDATE 8
#define CONTROL_BTN_SETTINGS 9
#define CONTROL_BTN_CHANGELOG 10
using namespace std;
using namespace ADDON;
using namespace XFILE;
CGUIDialogAddonInfo::CGUIDialogAddonInfo(void)
: CGUIDialog(WINDOW_DIALOG_ADDON_INFO, "DialogAddonInfo.xml")
{
m_item = CFileItemPtr(new CFileItem);
}
CGUIDialogAddonInfo::~CGUIDialogAddonInfo(void)
{
}
bool CGUIDialogAddonInfo::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
if (m_jobid)
CJobManager::GetInstance().CancelJob(m_jobid);
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BTN_UPDATE)
{
OnUpdate();
return true;
}
if (iControl == CONTROL_BTN_INSTALL)
{
if (!m_localAddon)
{
OnInstall();
return true;
}
else if (CGUIDialogYesNo::ShowAndGetInput(24037, 750, 0, 0))
{
OnUninstall();
return true;
}
}
else if (iControl == CONTROL_BTN_ENABLE)
{
OnEnable(!m_item->GetProperty("Addon.Enabled").Equals("true"));
return true;
}
else if (iControl == CONTROL_BTN_SETTINGS)
{
OnSettings();
return true;
}
else if (iControl == CONTROL_BTN_CHANGELOG)
{
OnChangeLog();
return true;
}
}
break;
default:
break;
}
return CGUIDialog::OnMessage(message);
}
void CGUIDialogAddonInfo::OnInitWindow()
{
UpdateControls();
CGUIDialog::OnInitWindow();
m_changelog = false;
}
void CGUIDialogAddonInfo::UpdateControls()
{
CStdString xbmcPath = _P("special://xbmc/addons");
bool isInstalled = NULL != m_localAddon.get();
bool isSystem = isInstalled && m_localAddon->Path().Left(xbmcPath.size()).Equals(xbmcPath);
bool isEnabled = isInstalled && m_item->GetProperty("Addon.Enabled").Equals("true");
bool isUpdatable = isInstalled && m_item->GetProperty("Addon.UpdateAvail").Equals("true");
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_INSTALL, (!isSystem && (m_item->GetProperty("Addon.Broken").IsEmpty() || isInstalled)));
SET_CONTROL_LABEL(CONTROL_BTN_INSTALL, isInstalled ? 24037 : 24038);
// TODO: System addons should be able to be disabled
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_ENABLE, isInstalled && !isSystem);
SET_CONTROL_LABEL(CONTROL_BTN_ENABLE, isEnabled ? 24021 : 24022);
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_UPDATE, isUpdatable);
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_SETTINGS, isInstalled && m_localAddon->HasSettings());
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_CHANGELOG, m_addon->Type() != ADDON_REPOSITORY);
}
void CGUIDialogAddonInfo::OnUpdate()
{
CGUIWindowAddonBrowser::InstallAddon(m_addon->ID(), true); // force install
Close();
}
void CGUIDialogAddonInfo::OnInstall()
{
CGUIWindowAddonBrowser::InstallAddon(m_addon->ID());
Close();
}
void CGUIDialogAddonInfo::OnUninstall()
{
if (!m_localAddon.get())
return;
// ensure the addon isn't disabled in our database
CAddonDatabase database;
database.Open();
database.DisableAddon(m_localAddon->ID(), false);
CGUIWindowAddonBrowser* window = (CGUIWindowAddonBrowser*)g_windowManager.GetWindow(WINDOW_ADDON_BROWSER);
CFileItemList list;
list.Add(CFileItemPtr(new CFileItem(m_localAddon->Path(),true)));
list[0]->Select(true);
CJobManager::GetInstance().AddJob(new CFileOperationJob(CFileOperationJob::ActionDelete,list,""),window);
CAddonMgr::Get().RemoveAddon(m_localAddon->ID());
Close();
}
void CGUIDialogAddonInfo::OnEnable(bool enable)
{
if (!m_localAddon.get())
return;
CAddonDatabase database;
database.Open();
database.DisableAddon(m_localAddon->ID(), !enable);
SetItem(m_item);
UpdateControls();
g_windowManager.SendMessage(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE);
}
void CGUIDialogAddonInfo::OnSettings()
{
CGUIDialogAddonSettings::ShowAndGetInput(m_localAddon);
}
void CGUIDialogAddonInfo::OnChangeLog()
{
CGUIDialogTextViewer* pDlgInfo = (CGUIDialogTextViewer*)g_windowManager.GetWindow(WINDOW_DIALOG_TEXT_VIEWER);
pDlgInfo->SetHeading(g_localizeStrings.Get(24054)+" - "+m_addon->Name());
if (m_item->GetProperty("Addon.Changelog").IsEmpty())
{
pDlgInfo->SetText(g_localizeStrings.Get(13413));
CFileItemList items;
items.Add(CFileItemPtr(new CFileItem(m_addon->ChangeLog(),false)));
items[0]->Select(true);
m_jobid = CJobManager::GetInstance().AddJob(
new CFileOperationJob(CFileOperationJob::ActionCopy,items,
"special://temp/"),this);
}
else
pDlgInfo->SetText(m_item->GetProperty("Addon.Changelog"));
m_changelog = true;
pDlgInfo->DoModal();
m_changelog = false;
}
bool CGUIDialogAddonInfo::ShowForItem(const CFileItemPtr& item)
{
CGUIDialogAddonInfo* dialog = (CGUIDialogAddonInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_ADDON_INFO);
if (!dialog)
return false;
if (!dialog->SetItem(item))
return false;
dialog->DoModal();
return true;
}
bool CGUIDialogAddonInfo::SetItem(const CFileItemPtr& item)
{
*m_item = *item;
// grab the local addon, if it's available
m_addon.reset();
if (CAddonMgr::Get().GetAddon(item->GetProperty("Addon.ID"), m_addon)) // sets m_addon if installed regardless of enabled state
m_item->SetProperty("Addon.Enabled", "true");
else
m_item->SetProperty("Addon.Enabled", "false");
m_item->SetProperty("Addon.Installed", m_addon ? "true" : "false");
m_localAddon = m_addon;
if (!m_addon)
{ // coming from a repository
CAddonDatabase database;
database.Open();
if (!database.GetAddon(item->GetProperty("Addon.ID"),m_addon))
return false; // can't find the addon
}
if (TranslateType(item->GetProperty("Addon.intType")) == ADDON_REPOSITORY)
{
CAddonDatabase database;
database.Open();
VECADDONS addons;
database.GetRepository(m_addon->ID(), addons);
int tot=0;
for (int i = ADDON_UNKNOWN+1;i<ADDON_VIZ_LIBRARY;++i)
{
int num=0;
for (unsigned int j=0;j<addons.size();++j)
{
if (addons[j]->Type() == (TYPE)i)
++num;
}
m_item->SetProperty(CStdString("Repo.") + TranslateType((TYPE)i), num);
tot += num;
}
m_item->SetProperty("Repo.Addons", tot);
}
return true;
}
void CGUIDialogAddonInfo::OnJobComplete(unsigned int jobID, bool success,
CJob* job)
{
if (!m_changelog)
return;
CGUIDialogTextViewer* pDlgInfo = (CGUIDialogTextViewer*)g_windowManager.GetWindow(WINDOW_DIALOG_TEXT_VIEWER);
m_jobid = 0;
if (!success)
{
pDlgInfo->SetText(g_localizeStrings.Get(195));
}
else
{
CFile file;
if (file.Open("special://temp/"+
CUtil::GetFileName(((CFileOperationJob*)job)->GetItems()[0]->m_strPath)))
{
char* temp = new char[(size_t)file.GetLength()+1];
file.Read(temp,file.GetLength());
temp[file.GetLength()] = '\0';
m_item->SetProperty("Addon.Changelog",temp);
pDlgInfo->SetText(temp);
delete[] temp;
}
}
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, WINDOW_DIALOG_TEXT_VIEWER, 0, GUI_MSG_UPDATE);
g_windowManager.SendThreadMessage(msg);
}
|