2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "GUIWindowPrograms.h"
24 #include "addons/GUIDialogAddonInfo.h"
26 #include "guilib/GUIWindowManager.h"
28 #include "settings/MediaSourceSettings.h"
29 #include "guilib/Key.h"
30 #include "guilib/LocalizeStrings.h"
31 #include "utils/log.h"
32 #include "utils/StringUtils.h"
34 #define CONTROL_BTNVIEWASICONS 2
35 #define CONTROL_BTNSORTBY 3
36 #define CONTROL_BTNSORTASC 4
37 #define CONTROL_LABELFILES 12
39 CGUIWindowPrograms::CGUIWindowPrograms(void)
40 : CGUIMediaWindow(WINDOW_PROGRAMS, "MyPrograms.xml")
42 m_thumbLoader.SetObserver(this);
44 m_rootDir.AllowNonLocalSources(false); // no nonlocal shares for this window please
48 CGUIWindowPrograms::~CGUIWindowPrograms(void)
52 bool CGUIWindowPrograms::OnMessage(CGUIMessage& message)
54 switch ( message.GetMessage() )
56 case GUI_MSG_WINDOW_DEINIT:
58 if (m_thumbLoader.IsLoading())
59 m_thumbLoader.StopThread();
63 case GUI_MSG_WINDOW_INIT:
65 m_dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
67 // is this the first time accessing this window?
68 if (m_vecItems->GetPath() == "?" && message.GetStringParam().empty())
69 message.SetStringParam(CMediaSourceSettings::Get().GetDefaultSource("programs"));
71 return CGUIMediaWindow::OnMessage(message);
77 if (m_viewControl.HasControl(message.GetSenderId())) // list/thumb control
79 int iAction = message.GetParam1();
80 int iItem = m_viewControl.GetSelectedItem();
81 if (iAction == ACTION_PLAYER_PLAY)
86 else if (iAction == ACTION_SHOW_INFO)
96 return CGUIMediaWindow::OnMessage(message);
99 void CGUIWindowPrograms::GetContextButtons(int itemNumber, CContextButtons &buttons)
101 if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
103 CFileItemPtr item = m_vecItems->Get(itemNumber);
104 if (item && !item->GetProperty("pluginreplacecontextitems").asBoolean())
106 if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://programs/" )
108 CGUIDialogContextMenu::GetContextButtons("programs", item, buttons);
112 if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript()))
113 buttons.Add(CONTEXT_BUTTON_INFO, 24003); // Add-on info
114 if (item->IsPlugin() || item->IsScript() || m_vecItems->IsPlugin())
115 buttons.Add(CONTEXT_BUTTON_PLUGIN_SETTINGS, 1045);
117 buttons.Add(CONTEXT_BUTTON_GOTO_ROOT, 20128); // Go to Root
120 CGUIMediaWindow::GetContextButtons(itemNumber, buttons);
123 bool CGUIWindowPrograms::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
125 CFileItemPtr item = (itemNumber >= 0 && itemNumber < m_vecItems->Size()) ? m_vecItems->Get(itemNumber) : CFileItemPtr();
127 if (CGUIDialogContextMenu::OnContextButton("programs", item, button))
134 case CONTEXT_BUTTON_GOTO_ROOT:
138 case CONTEXT_BUTTON_INFO:
145 return CGUIMediaWindow::OnContextButton(itemNumber, button);
148 bool CGUIWindowPrograms::Update(const CStdString &strDirectory, bool updateFilterPath /* = true */)
150 if (m_thumbLoader.IsLoading())
151 m_thumbLoader.StopThread();
153 if (!CGUIMediaWindow::Update(strDirectory, updateFilterPath))
156 m_thumbLoader.Load(*m_vecItems);
160 bool CGUIWindowPrograms::OnPlayMedia(int iItem)
162 if ( iItem < 0 || iItem >= (int)m_vecItems->Size() ) return false;
163 CFileItemPtr pItem = m_vecItems->Get(iItem);
167 return MEDIA_DETECT::CAutorun::PlayDiscAskResume(m_vecItems->Get(iItem)->GetPath());
170 if (pItem->m_bIsFolder) return false;
175 bool CGUIWindowPrograms::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
177 if (!CGUIMediaWindow::GetDirectory(strDirectory, items))
180 // don't allow the view state to change these
181 if (StringUtils::StartsWithNoCase(strDirectory, "addons://"))
183 for (int i=0;i<items.Size();++i)
185 items[i]->SetLabel2(items[i]->GetProperty("Addon.Version").asString());
186 items[i]->SetLabelPreformated(true);
193 CStdString CGUIWindowPrograms::GetStartFolder(const CStdString &dir)
195 if (dir.Equals("Plugins") || dir.Equals("Addons"))
196 return "addons://sources/executable/";
200 m_rootDir.GetSources(shares);
201 bool bIsSourceName = false;
202 int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName);
205 if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2)
207 CFileItem item(shares[iIndex]);
208 if (!g_passwordManager.IsItemUnlocked(&item,"programs"))
212 return shares[iIndex].strPath;
215 return CGUIMediaWindow::GetStartFolder(dir);
218 void CGUIWindowPrograms::OnInfo(int iItem)
220 if (iItem < 0 || iItem >= m_vecItems->Size())
223 CFileItemPtr item = m_vecItems->Get(iItem);
224 if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript()))
226 CGUIDialogAddonInfo::ShowForItem(item);