/
GUIWindowPrograms.cpp
229 lines (198 loc) · 6.19 KB
/
GUIWindowPrograms.cpp
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
/*
* Copyright (C) 2005-2013 Team XBMC
* http://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, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h"
#include "GUIWindowPrograms.h"
#include "Util.h"
#include "addons/GUIDialogAddonInfo.h"
#include "Autorun.h"
#include "guilib/GUIWindowManager.h"
#include "FileItem.h"
#include "settings/MediaSourceSettings.h"
#include "guilib/Key.h"
#include "guilib/LocalizeStrings.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#define CONTROL_BTNVIEWASICONS 2
#define CONTROL_BTNSORTBY 3
#define CONTROL_BTNSORTASC 4
#define CONTROL_LABELFILES 12
CGUIWindowPrograms::CGUIWindowPrograms(void)
: CGUIMediaWindow(WINDOW_PROGRAMS, "MyPrograms.xml")
{
m_thumbLoader.SetObserver(this);
m_dlgProgress = NULL;
m_rootDir.AllowNonLocalSources(false); // no nonlocal shares for this window please
}
CGUIWindowPrograms::~CGUIWindowPrograms(void)
{
}
bool CGUIWindowPrograms::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
if (m_thumbLoader.IsLoading())
m_thumbLoader.StopThread();
}
break;
case GUI_MSG_WINDOW_INIT:
{
m_dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
// is this the first time accessing this window?
if (m_vecItems->GetPath() == "?" && message.GetStringParam().empty())
message.SetStringParam(CMediaSourceSettings::Get().GetDefaultSource("programs"));
return CGUIMediaWindow::OnMessage(message);
}
break;
case GUI_MSG_CLICKED:
{
if (m_viewControl.HasControl(message.GetSenderId())) // list/thumb control
{
int iAction = message.GetParam1();
int iItem = m_viewControl.GetSelectedItem();
if (iAction == ACTION_PLAYER_PLAY)
{
OnPlayMedia(iItem);
return true;
}
else if (iAction == ACTION_SHOW_INFO)
{
OnInfo(iItem);
return true;
}
}
}
break;
}
return CGUIMediaWindow::OnMessage(message);
}
void CGUIWindowPrograms::GetContextButtons(int itemNumber, CContextButtons &buttons)
{
if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
return;
CFileItemPtr item = m_vecItems->Get(itemNumber);
if (item && !item->GetProperty("pluginreplacecontextitems").asBoolean())
{
if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://programs/" )
{
CGUIDialogContextMenu::GetContextButtons("programs", item, buttons);
}
else
{
if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript()))
buttons.Add(CONTEXT_BUTTON_INFO, 24003); // Add-on info
if (item->IsPlugin() || item->IsScript() || m_vecItems->IsPlugin())
buttons.Add(CONTEXT_BUTTON_PLUGIN_SETTINGS, 1045);
buttons.Add(CONTEXT_BUTTON_GOTO_ROOT, 20128); // Go to Root
}
}
CGUIMediaWindow::GetContextButtons(itemNumber, buttons);
}
bool CGUIWindowPrograms::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
CFileItemPtr item = (itemNumber >= 0 && itemNumber < m_vecItems->Size()) ? m_vecItems->Get(itemNumber) : CFileItemPtr();
if (CGUIDialogContextMenu::OnContextButton("programs", item, button))
{
Update("");
return true;
}
switch (button)
{
case CONTEXT_BUTTON_GOTO_ROOT:
Update("");
return true;
case CONTEXT_BUTTON_INFO:
OnInfo(itemNumber);
return true;
default:
break;
}
return CGUIMediaWindow::OnContextButton(itemNumber, button);
}
bool CGUIWindowPrograms::Update(const std::string &strDirectory, bool updateFilterPath /* = true */)
{
if (m_thumbLoader.IsLoading())
m_thumbLoader.StopThread();
if (!CGUIMediaWindow::Update(strDirectory, updateFilterPath))
return false;
m_thumbLoader.Load(*m_vecItems);
return true;
}
bool CGUIWindowPrograms::OnPlayMedia(int iItem)
{
if ( iItem < 0 || iItem >= (int)m_vecItems->Size() ) return false;
CFileItemPtr pItem = m_vecItems->Get(iItem);
#ifdef HAS_DVD_DRIVE
if (pItem->IsDVD())
return MEDIA_DETECT::CAutorun::PlayDiscAskResume(m_vecItems->Get(iItem)->GetPath());
#endif
if (pItem->m_bIsFolder) return false;
return false;
}
bool CGUIWindowPrograms::GetDirectory(const std::string &strDirectory, CFileItemList &items)
{
if (!CGUIMediaWindow::GetDirectory(strDirectory, items))
return false;
// don't allow the view state to change these
if (StringUtils::StartsWithNoCase(strDirectory, "addons://"))
{
for (int i=0;i<items.Size();++i)
{
items[i]->SetLabel2(items[i]->GetProperty("Addon.Version").asString());
items[i]->SetLabelPreformated(true);
}
}
return true;
}
std::string CGUIWindowPrograms::GetStartFolder(const std::string &dir)
{
std::string lower(dir); StringUtils::ToLower(lower);
if (lower == "plugins" || lower == "addons")
return "addons://sources/executable/";
SetupShares();
VECSOURCES shares;
m_rootDir.GetSources(shares);
bool bIsSourceName = false;
int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName);
if (iIndex > -1)
{
if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2)
{
CFileItem item(shares[iIndex]);
if (!g_passwordManager.IsItemUnlocked(&item,"programs"))
return "";
}
if (bIsSourceName)
return shares[iIndex].strPath;
return dir;
}
return CGUIMediaWindow::GetStartFolder(dir);
}
void CGUIWindowPrograms::OnInfo(int iItem)
{
if (iItem < 0 || iItem >= m_vecItems->Size())
return;
CFileItemPtr item = m_vecItems->Get(iItem);
if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript()))
{
CGUIDialogAddonInfo::ShowForItem(item);
}
}