diff options
Diffstat (limited to 'xbmc/programs')
-rw-r--r-- | xbmc/programs/CMakeLists.txt | 7 | ||||
-rw-r--r-- | xbmc/programs/GUIViewStatePrograms.cpp | 72 | ||||
-rw-r--r-- | xbmc/programs/GUIViewStatePrograms.h | 24 | ||||
-rw-r--r-- | xbmc/programs/GUIWindowPrograms.cpp | 185 | ||||
-rw-r--r-- | xbmc/programs/GUIWindowPrograms.h | 35 |
5 files changed, 323 insertions, 0 deletions
diff --git a/xbmc/programs/CMakeLists.txt b/xbmc/programs/CMakeLists.txt new file mode 100644 index 0000000..58ac8de --- /dev/null +++ b/xbmc/programs/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SOURCES GUIViewStatePrograms.cpp + GUIWindowPrograms.cpp) + +set(HEADERS GUIViewStatePrograms.h + GUIWindowPrograms.h) + +core_add_library(programs) diff --git a/xbmc/programs/GUIViewStatePrograms.cpp b/xbmc/programs/GUIViewStatePrograms.cpp new file mode 100644 index 0000000..05e4cfd --- /dev/null +++ b/xbmc/programs/GUIViewStatePrograms.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-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 "GUIViewStatePrograms.h" + +#include "FileItem.h" +#include "ServiceBroker.h" +#include "filesystem/Directory.h" +#include "guilib/LocalizeStrings.h" +#include "guilib/TextureManager.h" +#include "guilib/WindowIDs.h" +#include "settings/MediaSourceSettings.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" +#include "view/ViewState.h" +#include "view/ViewStateSettings.h" + +using namespace XFILE; + +CGUIViewStateWindowPrograms::CGUIViewStateWindowPrograms(const CFileItemList& items) : CGUIViewState(items) +{ + AddSortMethod(SortByLabel, 551, LABEL_MASKS("%K", "%I", "%L", ""), // Title, Size | Foldername, empty + CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_IGNORETHEWHENSORTING) ? SortAttributeIgnoreArticle : SortAttributeNone); + + const CViewState *viewState = CViewStateSettings::GetInstance().Get("programs"); + SetSortMethod(viewState->m_sortDescription); + SetViewAsControl(viewState->m_viewMode); + SetSortOrder(viewState->m_sortDescription.sortOrder); + + LoadViewState(items.GetPath(), WINDOW_PROGRAMS); +} + +void CGUIViewStateWindowPrograms::SaveViewState() +{ + SaveViewToDb(m_items.GetPath(), WINDOW_PROGRAMS, CViewStateSettings::GetInstance().Get("programs")); +} + +std::string CGUIViewStateWindowPrograms::GetLockType() +{ + return "programs"; +} + +std::string CGUIViewStateWindowPrograms::GetExtensions() +{ + return ".cut"; +} + +VECSOURCES& CGUIViewStateWindowPrograms::GetSources() +{ +#if defined(TARGET_ANDROID) + { + CMediaSource source; + source.strPath = "androidapp://sources/apps/"; + source.strName = g_localizeStrings.Get(20244); + if (CServiceBroker::GetGUI()->GetTextureManager().HasTexture("DefaultProgram.png")) + source.m_strThumbnailImage = "DefaultProgram.png"; + source.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; + source.m_ignore = true; + m_sources.emplace_back(std::move(source)); + } +#endif + + VECSOURCES *programSources = CMediaSourceSettings::GetInstance().GetSources("programs"); + AddOrReplace(*programSources, CGUIViewState::GetSources()); + return *programSources; +} + diff --git a/xbmc/programs/GUIViewStatePrograms.h b/xbmc/programs/GUIViewStatePrograms.h new file mode 100644 index 0000000..3892888 --- /dev/null +++ b/xbmc/programs/GUIViewStatePrograms.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2005-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. + */ + +#pragma once + +#include "view/GUIViewState.h" + +class CGUIViewStateWindowPrograms : public CGUIViewState +{ +public: + explicit CGUIViewStateWindowPrograms(const CFileItemList& items); + +protected: + void SaveViewState() override; + std::string GetLockType() override; + std::string GetExtensions() override; + VECSOURCES& GetSources() override; +}; + diff --git a/xbmc/programs/GUIWindowPrograms.cpp b/xbmc/programs/GUIWindowPrograms.cpp new file mode 100644 index 0000000..1e79c34 --- /dev/null +++ b/xbmc/programs/GUIWindowPrograms.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2005-2020 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 "GUIWindowPrograms.h" + +#include "Autorun.h" +#include "FileItem.h" +#include "GUIPassword.h" +#include "ServiceBroker.h" +#include "Util.h" +#include "addons/gui/GUIDialogAddonInfo.h" +#include "dialogs/GUIDialogMediaSource.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "input/Key.h" +#include "media/MediaLockState.h" +#include "settings/MediaSourceSettings.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) = default; + +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 = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogProgress>(WINDOW_DIALOG_PROGRESS); + + // is this the first time accessing this window? + if (m_vecItems->GetPath() == "?" && message.GetStringParam().empty()) + message.SetStringParam(CMediaSourceSettings::GetInstance().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) + { + OnItemInfo(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) + { + if ( m_vecItems->IsVirtualDirectoryRoot() || m_vecItems->GetPath() == "sources://programs/" ) + { + CGUIDialogContextMenu::GetContextButtons("programs", item, buttons); + } + } + 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; + } + return CGUIMediaWindow::OnContextButton(itemNumber, button); +} + +bool CGUIWindowPrograms::OnAddMediaSource() +{ + return CGUIDialogMediaSource::ShowAndAddMediaSource("programs"); +} + +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, const std::string&) +{ + if ( iItem < 0 || iItem >= 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; +} + +std::string CGUIWindowPrograms::GetStartFolder(const std::string &dir) +{ + std::string lower(dir); StringUtils::ToLower(lower); + if (lower == "plugins" || lower == "addons") + return "addons://sources/executable/"; + else if (lower == "androidapps") + return "androidapp://sources/apps/"; + + SetupShares(); + VECSOURCES shares; + m_rootDir.GetSources(shares); + bool bIsSourceName = false; + int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); + if (iIndex > -1) + { + if (iIndex < static_cast<int>(shares.size()) && shares[iIndex].m_iHasLock == LOCK_STATE_LOCKED) + { + 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::OnItemInfo(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); + } +} diff --git a/xbmc/programs/GUIWindowPrograms.h b/xbmc/programs/GUIWindowPrograms.h new file mode 100644 index 0000000..21156de --- /dev/null +++ b/xbmc/programs/GUIWindowPrograms.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2005-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. + */ + +#pragma once + +#include "ThumbLoader.h" +#include "dialogs/GUIDialogProgress.h" +#include "windows/GUIMediaWindow.h" + +class CGUIWindowPrograms : + public CGUIMediaWindow, public IBackgroundLoaderObserver +{ +public: + CGUIWindowPrograms(void); + ~CGUIWindowPrograms(void) override; + bool OnMessage(CGUIMessage& message) override; + virtual void OnItemInfo(int iItem); +protected: + void OnItemLoaded(CFileItem* pItem) override {}; + bool Update(const std::string& strDirectory, bool updateFilterPath = true) override; + bool OnPlayMedia(int iItem, const std::string& = "") override; + void GetContextButtons(int itemNumber, CContextButtons &buttons) override; + bool OnContextButton(int itemNumber, CONTEXT_BUTTON button) override; + bool OnAddMediaSource() override; + std::string GetStartFolder(const std::string &dir) override; + + CGUIDialogProgress* m_dlgProgress; + + CProgramThumbLoader m_thumbLoader; +}; |