2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIWindowPrograms.h"
13 #include "FileItemList.h"
14 #include "GUIPassword.h"
15 #include "ServiceBroker.h"
17 #include "addons/gui/GUIDialogAddonInfo.h"
18 #include "dialogs/GUIDialogMediaSource.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUIWindowManager.h"
21 #include "input/actions/ActionIDs.h"
22 #include "media/MediaLockState.h"
23 #include "settings/MediaSourceSettings.h"
24 #include "utils/StringUtils.h"
26 #define CONTROL_BTNVIEWASICONS 2
27 #define CONTROL_BTNSORTBY 3
28 #define CONTROL_BTNSORTASC 4
29 #define CONTROL_LABELFILES 12
31 CGUIWindowPrograms::CGUIWindowPrograms(void)
32 : CGUIMediaWindow(WINDOW_PROGRAMS
, "MyPrograms.xml")
34 m_thumbLoader
.SetObserver(this);
36 m_rootDir
.AllowNonLocalSources(false); // no nonlocal shares for this window please
40 CGUIWindowPrograms::~CGUIWindowPrograms(void) = default;
42 bool CGUIWindowPrograms::OnMessage(CGUIMessage
& message
)
44 switch ( message
.GetMessage() )
46 case GUI_MSG_WINDOW_DEINIT
:
48 if (m_thumbLoader
.IsLoading())
49 m_thumbLoader
.StopThread();
53 case GUI_MSG_WINDOW_INIT
:
55 m_dlgProgress
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogProgress
>(WINDOW_DIALOG_PROGRESS
);
57 // is this the first time accessing this window?
58 if (m_vecItems
->GetPath() == "?" && message
.GetStringParam().empty())
59 message
.SetStringParam(CMediaSourceSettings::GetInstance().GetDefaultSource("programs"));
61 return CGUIMediaWindow::OnMessage(message
);
67 if (m_viewControl
.HasControl(message
.GetSenderId())) // list/thumb control
69 int iAction
= message
.GetParam1();
70 int iItem
= m_viewControl
.GetSelectedItem();
71 if (iAction
== ACTION_PLAYER_PLAY
)
76 else if (iAction
== ACTION_SHOW_INFO
)
86 return CGUIMediaWindow::OnMessage(message
);
89 void CGUIWindowPrograms::GetContextButtons(int itemNumber
, CContextButtons
&buttons
)
91 if (itemNumber
< 0 || itemNumber
>= m_vecItems
->Size())
93 CFileItemPtr item
= m_vecItems
->Get(itemNumber
);
96 if ( m_vecItems
->IsVirtualDirectoryRoot() || m_vecItems
->GetPath() == "sources://programs/" )
98 CGUIDialogContextMenu::GetContextButtons("programs", item
, buttons
);
101 CGUIMediaWindow::GetContextButtons(itemNumber
, buttons
);
104 bool CGUIWindowPrograms::OnContextButton(int itemNumber
, CONTEXT_BUTTON button
)
106 CFileItemPtr item
= (itemNumber
>= 0 && itemNumber
< m_vecItems
->Size()) ? m_vecItems
->Get(itemNumber
) : CFileItemPtr();
108 if (CGUIDialogContextMenu::OnContextButton("programs", item
, button
))
113 return CGUIMediaWindow::OnContextButton(itemNumber
, button
);
116 bool CGUIWindowPrograms::OnAddMediaSource()
118 return CGUIDialogMediaSource::ShowAndAddMediaSource("programs");
121 bool CGUIWindowPrograms::Update(const std::string
&strDirectory
, bool updateFilterPath
/* = true */)
123 if (m_thumbLoader
.IsLoading())
124 m_thumbLoader
.StopThread();
126 if (!CGUIMediaWindow::Update(strDirectory
, updateFilterPath
))
129 m_thumbLoader
.Load(*m_vecItems
);
133 bool CGUIWindowPrograms::OnPlayMedia(int iItem
, const std::string
&)
135 if ( iItem
< 0 || iItem
>= m_vecItems
->Size() ) return false;
136 CFileItemPtr pItem
= m_vecItems
->Get(iItem
);
138 #ifdef HAS_OPTICAL_DRIVE
140 return MEDIA_DETECT::CAutorun::PlayDiscAskResume(m_vecItems
->Get(iItem
)->GetPath());
143 if (pItem
->m_bIsFolder
) return false;
148 std::string
CGUIWindowPrograms::GetStartFolder(const std::string
&dir
)
150 std::string
lower(dir
); StringUtils::ToLower(lower
);
151 if (lower
== "plugins" || lower
== "addons")
152 return "addons://sources/executable/";
153 else if (lower
== "androidapps")
154 return "androidapp://sources/apps/";
157 std::vector
<CMediaSource
> shares
;
158 m_rootDir
.GetSources(shares
);
159 bool bIsSourceName
= false;
160 int iIndex
= CUtil::GetMatchingSource(dir
, shares
, bIsSourceName
);
163 if (iIndex
< static_cast<int>(shares
.size()) && shares
[iIndex
].m_iHasLock
== LOCK_STATE_LOCKED
)
165 CFileItem
item(shares
[iIndex
]);
166 if (!g_passwordManager
.IsItemUnlocked(&item
,"programs"))
170 return shares
[iIndex
].strPath
;
173 return CGUIMediaWindow::GetStartFolder(dir
);
176 void CGUIWindowPrograms::OnItemInfo(int iItem
)
178 if (iItem
< 0 || iItem
>= m_vecItems
->Size())
181 CFileItemPtr item
= m_vecItems
->Get(iItem
);
182 if (!m_vecItems
->IsPlugin() && (item
->IsPlugin() || item
->IsScript()))
184 CGUIDialogAddonInfo::ShowForItem(item
);