From 649ee4ba49b3d9064541599f2f87e64d65fd8630 Mon Sep 17 00:00:00 2001 From: howie-f Date: Fri, 21 Feb 2020 09:12:16 +0100 Subject: [PATCH 1/5] Cleanup: fix include order --- .../resources/strings.po | 2 +- xbmc/CMakeLists.txt | 1 + xbmc/FileItem.cpp | 56 +++++++++---------- xbmc/GUIPassword.cpp | 19 ++++--- xbmc/LockType.h | 2 +- xbmc/MediaSource.cpp | 7 ++- xbmc/MediaSource.h | 5 +- xbmc/dialogs/GUIDialogContextMenu.cpp | 37 ++++++------ xbmc/filesystem/SourcesDirectory.cpp | 13 +++-- xbmc/games/windows/GUIWindowGames.cpp | 17 +++--- xbmc/interfaces/json-rpc/FileOperations.cpp | 13 +++-- .../httprequesthandler/HTTPVfsHandler.cpp | 2 +- xbmc/pictures/GUIWindowPictures.cpp | 31 +++++----- xbmc/playlists/PlayListXML.cpp | 9 +-- xbmc/programs/GUIWindowPrograms.cpp | 13 +++-- xbmc/settings/MediaSourceSettings.cpp | 15 ++--- xbmc/utils/FileUtils.cpp | 19 ++++--- 17 files changed, 137 insertions(+), 124 deletions(-) diff --git a/addons/resource.language.en_gb/resources/strings.po b/addons/resource.language.en_gb/resources/strings.po index 07a66466143e3..03b5894ef4128 100644 --- a/addons/resource.language.en_gb/resources/strings.po +++ b/addons/resource.language.en_gb/resources/strings.po @@ -5753,7 +5753,7 @@ msgstr "" #: xbmc/dialogs/GUIDialogGamepad.cpp #: xbmc/dialogs/GUIDialogNumeric.cpp msgctxt "#12343" -msgid "retries left " +msgid "retries left" msgstr "" #: xbmc/dialogs/GUIDialogGamepad.cpp diff --git a/xbmc/CMakeLists.txt b/xbmc/CMakeLists.txt index 50eadc1dc94e3..863fb854bdcb3 100644 --- a/xbmc/CMakeLists.txt +++ b/xbmc/CMakeLists.txt @@ -65,6 +65,7 @@ set(HEADERS AppParamParser.h IProgressCallback.h InfoScanner.h LangInfo.h + LockType.h MediaSource.h NfoFile.h PartyModeManager.h diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 9118fa2eaba0b..8438461fab2b3 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -1,63 +1,63 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * 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 - #include "FileItem.h" + +#include "CueDocument.h" #include "ServiceBroker.h" -#include "guilib/LocalizeStrings.h" -#include "utils/StringUtils.h" -#include "utils/URIUtils.h" -#include "utils/Archive.h" +#include "URL.h" #include "Util.h" -#include "playlists/PlayListFactory.h" -#include "utils/Crc32.h" +#include "events/IEvent.h" +#include "filesystem/CurlFile.h" #include "filesystem/Directory.h" #include "filesystem/File.h" -#include "filesystem/StackDirectory.h" -#include "filesystem/CurlFile.h" #include "filesystem/MultiPathDirectory.h" #include "filesystem/MusicDatabaseDirectory.h" +#include "filesystem/StackDirectory.h" #include "filesystem/VideoDatabaseDirectory.h" #include "filesystem/VideoDatabaseDirectory/QueryParams.h" -#include "games/addons/GameClient.h" #include "games/GameUtils.h" +#include "games/addons/GameClient.h" #include "games/tags/GameInfoTag.h" -#include "music/tags/MusicInfoTagLoaderFactory.h" -#include "CueDocument.h" -#include "video/VideoDatabase.h" +#include "guilib/LocalizeStrings.h" +#include "music/Album.h" +#include "music/Artist.h" #include "music/MusicDatabase.h" +#include "music/tags/MusicInfoTag.h" +#include "music/tags/MusicInfoTagLoaderFactory.h" +#include "pictures/PictureInfoTag.h" +#include "playlists/PlayListFactory.h" #include "pvr/PVRManager.h" -#include "pvr/channels/PVRChannelGroupsContainer.h" #include "pvr/channels/PVRChannel.h" +#include "pvr/channels/PVRChannelGroupsContainer.h" #include "pvr/epg/Epg.h" #include "pvr/recordings/PVRRecording.h" #include "pvr/timers/PVRTimerInfoTag.h" -#include "video/Bookmark.h" -#include "video/VideoInfoTag.h" -#include "threads/SingleLock.h" -#include "music/tags/MusicInfoTag.h" -#include "pictures/PictureInfoTag.h" -#include "music/Artist.h" -#include "music/Album.h" -#include "URL.h" #include "settings/AdvancedSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" +#include "threads/SingleLock.h" +#include "utils/Archive.h" +#include "utils/Crc32.h" #include "utils/FileExtensionProvider.h" -#include "utils/RegExp.h" -#include "utils/log.h" -#include "utils/Variant.h" #include "utils/Mime.h" #include "utils/Random.h" -#include "events/IEvent.h" +#include "utils/RegExp.h" +#include "utils/StringUtils.h" +#include "utils/URIUtils.h" +#include "utils/Variant.h" +#include "utils/log.h" +#include "video/Bookmark.h" +#include "video/VideoDatabase.h" +#include "video/VideoInfoTag.h" #include +#include using namespace KODI; using namespace XFILE; diff --git a/xbmc/GUIPassword.cpp b/xbmc/GUIPassword.cpp index ef4859fa8f53a..9b4348954340a 100644 --- a/xbmc/GUIPassword.cpp +++ b/xbmc/GUIPassword.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,27 +7,28 @@ */ #include "GUIPassword.h" + +#include "FileItem.h" #include "GUIUserMessages.h" #include "ServiceBroker.h" -#include "messaging/ApplicationMessenger.h" +#include "Util.h" #include "dialogs/GUIDialogGamepad.h" +#include "dialogs/GUIDialogNumeric.h" #include "guilib/GUIComponent.h" #include "guilib/GUIKeyboardFactory.h" -#include "dialogs/GUIDialogNumeric.h" +#include "guilib/GUIWindowManager.h" +#include "guilib/LocalizeStrings.h" +#include "messaging/ApplicationMessenger.h" +#include "messaging/helpers/DialogOKHelper.h" #include "profiles/ProfileManager.h" #include "profiles/dialogs/GUIDialogLockSettings.h" #include "profiles/dialogs/GUIDialogProfileSettings.h" -#include "Util.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" -#include "guilib/GUIWindowManager.h" -#include "FileItem.h" -#include "guilib/LocalizeStrings.h" -#include "messaging/helpers/DialogOKHelper.h" #include "utils/StringUtils.h" -#include "view/ViewStateSettings.h" #include "utils/Variant.h" +#include "view/ViewStateSettings.h" #include diff --git a/xbmc/LockType.h b/xbmc/LockType.h index 8bdc237109a32..9659046db714e 100644 --- a/xbmc/LockType.h +++ b/xbmc/LockType.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later diff --git a/xbmc/MediaSource.cpp b/xbmc/MediaSource.cpp index 7b42efa2da5a4..76ddba9d90cb8 100644 --- a/xbmc/MediaSource.cpp +++ b/xbmc/MediaSource.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,11 +7,12 @@ */ #include "MediaSource.h" -#include "Util.h" + #include "URL.h" +#include "Util.h" #include "filesystem/MultiPathDirectory.h" -#include "utils/URIUtils.h" #include "utils/StringUtils.h" +#include "utils/URIUtils.h" using namespace XFILE; diff --git a/xbmc/MediaSource.h b/xbmc/MediaSource.h index ea14f9281e6e3..9fa72df8bf5eb 100644 --- a/xbmc/MediaSource.h +++ b/xbmc/MediaSource.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -8,9 +8,10 @@ #pragma once +#include "LockType.h" + #include #include -#include "LockType.h" /*! \ingroup windows diff --git a/xbmc/dialogs/GUIDialogContextMenu.cpp b/xbmc/dialogs/GUIDialogContextMenu.cpp index 5841234261f25..f12355421c4b5 100644 --- a/xbmc/dialogs/GUIDialogContextMenu.cpp +++ b/xbmc/dialogs/GUIDialogContextMenu.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,33 +7,34 @@ */ #include "GUIDialogContextMenu.h" -#include "guilib/GUIComponent.h" -#include "guilib/GUIButtonControl.h" -#include "guilib/GUIControlGroupList.h" + +#include "FileItem.h" #include "GUIDialogFileBrowser.h" -#include "GUIUserMessages.h" +#include "GUIDialogMediaSource.h" +#include "GUIDialogYesNo.h" #include "GUIPassword.h" +#include "GUIUserMessages.h" #include "ServiceBroker.h" +#include "TextureCache.h" +#include "URL.h" #include "Util.h" -#include "utils/URIUtils.h" +#include "addons/Scraper.h" +#include "filesystem/File.h" +#include "guilib/GUIButtonControl.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIControlGroupList.h" +#include "guilib/GUIWindowManager.h" +#include "guilib/LocalizeStrings.h" +#include "input/Key.h" +#include "profiles/ProfileManager.h" +#include "profiles/dialogs/GUIDialogLockSettings.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" -#include "GUIDialogMediaSource.h" -#include "profiles/ProfileManager.h" -#include "profiles/dialogs/GUIDialogLockSettings.h" #include "storage/MediaManager.h" -#include "guilib/GUIWindowManager.h" -#include "input/Key.h" -#include "GUIDialogYesNo.h" -#include "FileItem.h" -#include "filesystem/File.h" -#include "guilib/LocalizeStrings.h" -#include "TextureCache.h" -#include "URL.h" #include "utils/StringUtils.h" +#include "utils/URIUtils.h" #include "utils/Variant.h" -#include "addons/Scraper.h" #define BACKGROUND_IMAGE 999 #define GROUP_LIST 996 diff --git a/xbmc/filesystem/SourcesDirectory.cpp b/xbmc/filesystem/SourcesDirectory.cpp index 702b2cd6292e2..fd0dcfc4052af 100644 --- a/xbmc/filesystem/SourcesDirectory.cpp +++ b/xbmc/filesystem/SourcesDirectory.cpp @@ -1,22 +1,23 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * 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 "ServiceBroker.h" #include "SourcesDirectory.h" -#include "utils/URIUtils.h" + +#include "File.h" +#include "FileItem.h" +#include "ServiceBroker.h" #include "URL.h" #include "Util.h" -#include "FileItem.h" -#include "File.h" +#include "guilib/TextureManager.h" #include "profiles/ProfileManager.h" #include "settings/MediaSourceSettings.h" -#include "guilib/TextureManager.h" #include "storage/MediaManager.h" +#include "utils/URIUtils.h" using namespace XFILE; diff --git a/xbmc/games/windows/GUIWindowGames.cpp b/xbmc/games/windows/GUIWindowGames.cpp index 4721a940ac5d4..97fe45071781c 100644 --- a/xbmc/games/windows/GUIWindowGames.cpp +++ b/xbmc/games/windows/GUIWindowGames.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2018 Team Kodi + * Copyright (C) 2012-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,24 +7,25 @@ */ #include "GUIWindowGames.h" -#include "addons/GUIDialogAddonInfo.h" + #include "Application.h" +#include "FileItem.h" +#include "GUIPassword.h" +#include "PlayListPlayer.h" +#include "ServiceBroker.h" +#include "URL.h" +#include "Util.h" +#include "addons/GUIDialogAddonInfo.h" #include "dialogs/GUIDialogContextMenu.h" #include "dialogs/GUIDialogMediaSource.h" #include "dialogs/GUIDialogProgress.h" -#include "FileItem.h" #include "games/addons/GameClient.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/WindowIDs.h" -#include "GUIPassword.h" -#include "PlayListPlayer.h" -#include "ServiceBroker.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" -#include "URL.h" -#include "Util.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" diff --git a/xbmc/interfaces/json-rpc/FileOperations.cpp b/xbmc/interfaces/json-rpc/FileOperations.cpp index b4d316db30458..7919452155ba5 100644 --- a/xbmc/interfaces/json-rpc/FileOperations.cpp +++ b/xbmc/interfaces/json-rpc/FileOperations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,21 +7,22 @@ */ #include "FileOperations.h" -#include "VideoLibrary.h" + #include "AudioLibrary.h" +#include "FileItem.h" #include "MediaSource.h" #include "ServiceBroker.h" +#include "URL.h" +#include "Util.h" +#include "VideoLibrary.h" #include "filesystem/Directory.h" #include "filesystem/File.h" -#include "FileItem.h" #include "settings/AdvancedSettings.h" #include "settings/MediaSourceSettings.h" #include "settings/SettingsComponent.h" -#include "Util.h" -#include "URL.h" #include "utils/FileExtensionProvider.h" -#include "utils/URIUtils.h" #include "utils/FileUtils.h" +#include "utils/URIUtils.h" #include "utils/Variant.h" #include "video/VideoDatabase.h" diff --git a/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp b/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp index dd938d62983c1..3bbaf8ef38084 100644 --- a/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp +++ b/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2018 Team Kodi + * Copyright (C) 2011-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later diff --git a/xbmc/pictures/GUIWindowPictures.cpp b/xbmc/pictures/GUIWindowPictures.cpp index 8448b509f3dd2..a3e691878b58f 100644 --- a/xbmc/pictures/GUIWindowPictures.cpp +++ b/xbmc/pictures/GUIWindowPictures.cpp @@ -1,41 +1,42 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * 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 "threads/SystemClock.h" #include "GUIWindowPictures.h" + +#include "Application.h" +#include "Autorun.h" +#include "GUIDialogPictureInfo.h" +#include "GUIPassword.h" +#include "GUIWindowSlideShow.h" +#include "PictureInfoLoader.h" +#include "PlayListPlayer.h" #include "ServiceBroker.h" #include "URL.h" #include "Util.h" -#include "Application.h" -#include "GUIPassword.h" -#include "GUIDialogPictureInfo.h" #include "addons/GUIDialogAddonInfo.h" #include "dialogs/GUIDialogMediaSource.h" #include "dialogs/GUIDialogProgress.h" -#include "playlists/PlayListFactory.h" -#include "PictureInfoLoader.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" -#include "view/GUIViewState.h" +#include "interfaces/AnnouncementManager.h" #include "messaging/helpers/DialogOKHelper.h" -#include "PlayListPlayer.h" #include "playlists/PlayList.h" +#include "playlists/PlayListFactory.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" -#include "utils/log.h" -#include "utils/URIUtils.h" -#include "utils/Variant.h" -#include "Autorun.h" -#include "interfaces/AnnouncementManager.h" +#include "threads/SystemClock.h" #include "utils/SortUtils.h" #include "utils/StringUtils.h" -#include "GUIWindowSlideShow.h" +#include "utils/URIUtils.h" +#include "utils/Variant.h" +#include "utils/log.h" +#include "view/GUIViewState.h" #ifdef TARGET_POSIX #include "platform/linux/XTimeUtils.h" diff --git a/xbmc/playlists/PlayListXML.cpp b/xbmc/playlists/PlayListXML.cpp index 8d13db3abf28f..61041ff298f7a 100644 --- a/xbmc/playlists/PlayListXML.cpp +++ b/xbmc/playlists/PlayListXML.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,13 +7,14 @@ */ #include "PlayListXML.h" -#include "filesystem/File.h" + #include "Util.h" -#include "utils/log.h" +#include "filesystem/File.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" -#include "utils/XMLUtils.h" #include "utils/Variant.h" +#include "utils/XMLUtils.h" +#include "utils/log.h" using namespace PLAYLIST; using namespace XFILE; diff --git a/xbmc/programs/GUIWindowPrograms.cpp b/xbmc/programs/GUIWindowPrograms.cpp index 813d6d7b97732..4fff72aaeb2ff 100644 --- a/xbmc/programs/GUIWindowPrograms.cpp +++ b/xbmc/programs/GUIWindowPrograms.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,18 +7,19 @@ */ #include "GUIWindowPrograms.h" -#include "Util.h" + +#include "Autorun.h" +#include "FileItem.h" #include "GUIPassword.h" +#include "ServiceBroker.h" +#include "Util.h" #include "addons/GUIDialogAddonInfo.h" -#include "Autorun.h" #include "dialogs/GUIDialogMediaSource.h" #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" -#include "FileItem.h" -#include "settings/MediaSourceSettings.h" #include "input/Key.h" +#include "settings/MediaSourceSettings.h" #include "utils/StringUtils.h" -#include "ServiceBroker.h" #define CONTROL_BTNVIEWASICONS 2 #define CONTROL_BTNSORTBY 3 diff --git a/xbmc/settings/MediaSourceSettings.cpp b/xbmc/settings/MediaSourceSettings.cpp index 48120af130501..34167e2157222 100644 --- a/xbmc/settings/MediaSourceSettings.cpp +++ b/xbmc/settings/MediaSourceSettings.cpp @@ -1,27 +1,28 @@ /* - * Copyright (C) 2013-2018 Team Kodi + * Copyright (C) 2013-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 -#include - #include "MediaSourceSettings.h" + +#include "ServiceBroker.h" #include "URL.h" #include "Util.h" #include "filesystem/File.h" +#include "network/WakeOnAccess.h" #include "profiles/ProfileManager.h" #include "settings/SettingsComponent.h" -#include "utils/log.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/XBMCTinyXML.h" #include "utils/XMLUtils.h" -#include "network/WakeOnAccess.h" -#include "ServiceBroker.h" +#include "utils/log.h" + +#include +#include #define SOURCES_FILE "sources.xml" #define XML_SOURCES "sources" diff --git a/xbmc/utils/FileUtils.cpp b/xbmc/utils/FileUtils.cpp index 9f19808b4e9df..cc0455af747b6 100644 --- a/xbmc/utils/FileUtils.cpp +++ b/xbmc/utils/FileUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2018 Team Kodi + * Copyright (C) 2010-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,24 +7,25 @@ */ #include "FileUtils.h" -#include "ServiceBroker.h" -#include "guilib/GUIKeyboardFactory.h" -#include "utils/log.h" -#include "guilib/LocalizeStrings.h" -#include "JobManager.h" + #include "FileOperationJob.h" +#include "JobManager.h" +#include "ServiceBroker.h" +#include "StringUtils.h" #include "URIUtils.h" +#include "URL.h" +#include "Util.h" #include "filesystem/MultiPathDirectory.h" #include "filesystem/SpecialProtocol.h" #include "filesystem/StackDirectory.h" +#include "guilib/GUIKeyboardFactory.h" +#include "guilib/LocalizeStrings.h" #include "settings/MediaSourceSettings.h" -#include "Util.h" -#include "StringUtils.h" -#include "URL.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" #include "storage/MediaManager.h" #include "utils/Variant.h" +#include "utils/log.h" #if defined(TARGET_WINDOWS) #include "platform/win32/WIN32Util.h" From fade6af5d8df061e203cec404c5e21d15c73afaa Mon Sep 17 00:00:00 2001 From: howie-f Date: Fri, 21 Feb 2020 09:12:17 +0100 Subject: [PATCH 2/5] Introduce and refactor MediaLockState enum --- xbmc/FileItem.cpp | 3 ++- xbmc/GUIPassword.cpp | 15 ++++++++------- xbmc/MediaSource.cpp | 3 ++- xbmc/MediaSource.h | 3 ++- xbmc/dialogs/GUIDialogContextMenu.cpp | 18 ++++++++++++------ xbmc/filesystem/SourcesDirectory.cpp | 4 +++- xbmc/games/windows/GUIWindowGames.cpp | 3 ++- xbmc/interfaces/json-rpc/FileOperations.cpp | 3 ++- xbmc/media/CMakeLists.txt | 3 ++- xbmc/media/MediaLockState.h | 16 ++++++++++++++++ .../httprequesthandler/HTTPVfsHandler.cpp | 7 ++++--- xbmc/pictures/GUIWindowPictures.cpp | 3 ++- xbmc/playlists/PlayListXML.cpp | 5 +++-- xbmc/programs/GUIWindowPrograms.cpp | 3 ++- xbmc/settings/MediaSourceSettings.cpp | 3 ++- xbmc/utils/FileUtils.cpp | 10 +++++++--- 16 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 xbmc/media/MediaLockState.h diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index 8438461fab2b3..c576f13e47c04 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -25,6 +25,7 @@ #include "games/addons/GameClient.h" #include "games/tags/GameInfoTag.h" #include "guilib/LocalizeStrings.h" +#include "media/MediaLockState.h" #include "music/Album.h" #include "music/Artist.h" #include "music/MusicDatabase.h" @@ -493,7 +494,7 @@ void CFileItem::Initialize() m_idepth = 1; m_iLockMode = LOCK_MODE_EVERYONE; m_iBadPwdCount = 0; - m_iHasLock = 0; + m_iHasLock = LOCK_STATE_NO_LOCK; m_bCanQueue = true; m_specialSort = SortSpecialNone; m_doContentLookup = true; diff --git a/xbmc/GUIPassword.cpp b/xbmc/GUIPassword.cpp index 9b4348954340a..37d9a8144ebcf 100644 --- a/xbmc/GUIPassword.cpp +++ b/xbmc/GUIPassword.cpp @@ -18,6 +18,7 @@ #include "guilib/GUIKeyboardFactory.h" #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" +#include "media/MediaLockState.h" #include "messaging/ApplicationMessenger.h" #include "messaging/helpers/DialogOKHelper.h" #include "profiles/ProfileManager.h" @@ -52,7 +53,7 @@ bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string &strType) if (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE) return true; - while (pItem->m_iHasLock > 1) + while (pItem->m_iHasLock > LOCK_STATE_LOCK_BUT_UNLOCKED) { std::string strLockCode = pItem->m_strLockCode; std::string strLabel = pItem->GetLabel(); @@ -89,7 +90,7 @@ bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string &strType) { // password entry succeeded pItem->m_iBadPwdCount = 0; - pItem->m_iHasLock = 1; + pItem->m_iHasLock = LOCK_STATE_LOCK_BUT_UNLOCKED; g_passwordManager.LockSource(strType,strLabel,false); sprintf(buffer,"%i",pItem->m_iBadPwdCount); CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount", buffer); @@ -459,9 +460,9 @@ bool CGUIPassword::LockSource(const std::string& strType, const std::string& str { if (it->strName == strName) { - if (it->m_iHasLock > 0) + if (it->m_iHasLock > LOCK_STATE_NO_LOCK) { - it->m_iHasLock = bState?2:1; + it->m_iHasLock = bState ? LOCK_STATE_LOCKED : LOCK_STATE_LOCK_BUT_UNLOCKED; bResult = true; } break; @@ -482,7 +483,7 @@ void CGUIPassword::LockSources(bool lock) VECSOURCES *shares = CMediaSourceSettings::GetInstance().GetSources(strType); for (IVECSOURCES it=shares->begin();it != shares->end();++it) if (it->m_iLockMode != LOCK_MODE_EVERYONE) - it->m_iHasLock = lock ? 2 : 1; + it->m_iHasLock = lock ? LOCK_STATE_LOCKED : LOCK_STATE_LOCK_BUT_UNLOCKED; } CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_SOURCES); CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg); @@ -498,7 +499,7 @@ void CGUIPassword::RemoveSourceLocks() for (IVECSOURCES it=shares->begin();it != shares->end();++it) if (it->m_iLockMode != LOCK_MODE_EVERYONE) // remove old info { - it->m_iHasLock = 0; + it->m_iHasLock = LOCK_STATE_NO_LOCK; it->m_iLockMode = LOCK_MODE_EVERYONE; CMediaSourceSettings::GetInstance().UpdateSource(strType, it->strName, "lockmode", "0"); // removes locks from xml } @@ -520,7 +521,7 @@ bool CGUIPassword::IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES int iIndex = CUtil::GetMatchingSource(strPath, vecSources, bName); if (iIndex > -1 && iIndex < (int)vecSources.size()) - if (vecSources[iIndex].m_iHasLock < 2) + if (vecSources[iIndex].m_iHasLock < LOCK_STATE_LOCKED) return true; return false; diff --git a/xbmc/MediaSource.cpp b/xbmc/MediaSource.cpp index 76ddba9d90cb8..6782ca3f1c082 100644 --- a/xbmc/MediaSource.cpp +++ b/xbmc/MediaSource.cpp @@ -11,6 +11,7 @@ #include "URL.h" #include "Util.h" #include "filesystem/MultiPathDirectory.h" +#include "media/MediaLockState.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" @@ -41,7 +42,7 @@ void CMediaSource::FromNameAndPaths(const std::string &category, const std::stri m_iLockMode = LOCK_MODE_EVERYONE; m_strLockCode = "0"; m_iBadPwdCount = 0; - m_iHasLock = 0; + m_iHasLock = LOCK_STATE_NO_LOCK; m_allowSharing = true; if (URIUtils::IsMultiPath(strPath)) diff --git a/xbmc/MediaSource.h b/xbmc/MediaSource.h index 9fa72df8bf5eb..1afbea2ac7555 100644 --- a/xbmc/MediaSource.h +++ b/xbmc/MediaSource.h @@ -9,6 +9,7 @@ #pragma once #include "LockType.h" +#include "media/MediaLockState.h" #include #include @@ -79,7 +80,7 @@ class CMediaSource final */ LockType m_iLockMode = LOCK_MODE_EVERYONE; std::string m_strLockCode; ///< Input code for Lock UI to verify, can be chosen freely. - int m_iHasLock = 0; + int m_iHasLock = LOCK_STATE_NO_LOCK; int m_iBadPwdCount = 0; ///< Number of wrong passwords user has entered since share was last unlocked std::string m_strThumbnailImage; ///< Path to a thumbnail image for the share, or blank for default diff --git a/xbmc/dialogs/GUIDialogContextMenu.cpp b/xbmc/dialogs/GUIDialogContextMenu.cpp index f12355421c4b5..af92fc2430fcb 100644 --- a/xbmc/dialogs/GUIDialogContextMenu.cpp +++ b/xbmc/dialogs/GUIDialogContextMenu.cpp @@ -26,6 +26,7 @@ #include "guilib/GUIWindowManager.h" #include "guilib/LocalizeStrings.h" #include "input/Key.h" +#include "media/MediaLockState.h" #include "profiles/ProfileManager.h" #include "profiles/dialogs/GUIDialogLockSettings.h" #include "settings/MediaSourceSettings.h" @@ -249,11 +250,15 @@ void CGUIDialogContextMenu::GetContextButtons(const std::string &type, const CFi } if (share && LOCK_MODE_EVERYONE != CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetMasterProfile().getLockMode()) { - if (share->m_iHasLock == 0 && (CServiceBroker::GetSettingsComponent()->GetProfileManager()->GetCurrentProfile().canWriteSources() || g_passwordManager.bMasterUser)) + if (share->m_iHasLock == LOCK_STATE_NO_LOCK && (CServiceBroker::GetSettingsComponent() + ->GetProfileManager() + ->GetCurrentProfile() + .canWriteSources() || + g_passwordManager.bMasterUser)) buttons.Add(CONTEXT_BUTTON_ADD_LOCK, 12332); - else if (share->m_iHasLock == 1) + else if (share->m_iHasLock == LOCK_STATE_LOCK_BUT_UNLOCKED) buttons.Add(CONTEXT_BUTTON_REMOVE_LOCK, 12335); - else if (share->m_iHasLock == 2) + else if (share->m_iHasLock == LOCK_STATE_LOCKED) { buttons.Add(CONTEXT_BUTTON_REMOVE_LOCK, 12335); @@ -267,7 +272,7 @@ void CGUIDialogContextMenu::GetContextButtons(const std::string &type, const CFi buttons.Add(CONTEXT_BUTTON_CHANGE_LOCK, 12356); } } - if (share && !g_passwordManager.bMasterUser && item->m_iHasLock == 1) + if (share && !g_passwordManager.bMasterUser && item->m_iHasLock == LOCK_STATE_LOCK_BUT_UNLOCKED) buttons.Add(CONTEXT_BUTTON_REACTIVATE_LOCK, 12353); } @@ -437,7 +442,7 @@ bool CGUIDialogContextMenu::OnContextButton(const std::string &type, const CFile if (!CGUIDialogLockSettings::ShowAndGetLock(share->m_iLockMode,strNewPassword)) return false; // password entry and re-entry succeeded, write out the lock data - share->m_iHasLock = 2; + share->m_iHasLock = LOCK_STATE_LOCKED; CMediaSourceSettings::GetInstance().UpdateSource(type, share->strName, "lockcode", strNewPassword); strNewPassword = StringUtils::Format("%i", share->m_iLockMode); CMediaSourceSettings::GetInstance().UpdateSource(type, share->strName, "lockmode", strNewPassword); @@ -465,10 +470,11 @@ bool CGUIDialogContextMenu::OnContextButton(const std::string &type, const CFile if (!g_passwordManager.IsMasterLockUnlocked(true)) return false; + // prompt user if they want to really remove the lock if (!CGUIDialogYesNo::ShowAndGetInput(CVariant{12335}, CVariant{750})) return false; - share->m_iHasLock = 0; + share->m_iHasLock = LOCK_STATE_NO_LOCK; CMediaSourceSettings::GetInstance().UpdateSource(type, share->strName, "lockmode", "0"); CMediaSourceSettings::GetInstance().UpdateSource(type, share->strName, "lockcode", "0"); CMediaSourceSettings::GetInstance().UpdateSource(type, share->strName, "badpwdcount", "0"); diff --git a/xbmc/filesystem/SourcesDirectory.cpp b/xbmc/filesystem/SourcesDirectory.cpp index fd0dcfc4052af..08d1c11363c39 100644 --- a/xbmc/filesystem/SourcesDirectory.cpp +++ b/xbmc/filesystem/SourcesDirectory.cpp @@ -14,6 +14,7 @@ #include "URL.h" #include "Util.h" #include "guilib/TextureManager.h" +#include "media/MediaLockState.h" #include "profiles/ProfileManager.h" #include "settings/MediaSourceSettings.h" #include "storage/MediaManager.h" @@ -88,7 +89,8 @@ bool CSourcesDirectory::GetDirectory(const VECSOURCES &sources, CFileItemList &i strIcon = "DefaultHardDisk.png"; pItem->SetIconImage(strIcon); - if (share.m_iHasLock == 2 && m_profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE) + if (share.m_iHasLock == LOCK_STATE_LOCKED && + m_profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE) pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_LOCKED); else pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_NONE); diff --git a/xbmc/games/windows/GUIWindowGames.cpp b/xbmc/games/windows/GUIWindowGames.cpp index 97fe45071781c..bef066dfb111a 100644 --- a/xbmc/games/windows/GUIWindowGames.cpp +++ b/xbmc/games/windows/GUIWindowGames.cpp @@ -23,6 +23,7 @@ #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "guilib/WindowIDs.h" +#include "media/MediaLockState.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -292,7 +293,7 @@ std::string CGUIWindowGames::GetStartFolder(const std::string &dir) int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); if (iIndex >= 0) { - if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2) + if (iIndex < static_cast(shares.size()) && shares[iIndex].m_iHasLock == LOCK_STATE_LOCKED) { CFileItem item(shares[iIndex]); if (!g_passwordManager.IsItemUnlocked(&item, "games")) diff --git a/xbmc/interfaces/json-rpc/FileOperations.cpp b/xbmc/interfaces/json-rpc/FileOperations.cpp index 7919452155ba5..b4982117311ff 100644 --- a/xbmc/interfaces/json-rpc/FileOperations.cpp +++ b/xbmc/interfaces/json-rpc/FileOperations.cpp @@ -17,6 +17,7 @@ #include "VideoLibrary.h" #include "filesystem/Directory.h" #include "filesystem/File.h" +#include "media/MediaLockState.h" #include "settings/AdvancedSettings.h" #include "settings/MediaSourceSettings.h" #include "settings/SettingsComponent.h" @@ -41,7 +42,7 @@ JSONRPC_STATUS CFileOperations::GetRootDirectory(const std::string &method, ITra for (unsigned int i = 0; i < (unsigned int)sources->size(); i++) { // Do not show sources which are locked - if (sources->at(i).m_iHasLock == 2) + if (sources->at(i).m_iHasLock == LOCK_STATE_LOCKED) continue; items.Add(CFileItemPtr(new CFileItem(sources->at(i)))); diff --git a/xbmc/media/CMakeLists.txt b/xbmc/media/CMakeLists.txt index dc8f67a834ae8..76b0737684045 100644 --- a/xbmc/media/CMakeLists.txt +++ b/xbmc/media/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES MediaType.cpp) -set(HEADERS MediaType.h) +set(HEADERS MediaLockState.h + MediaType.h) core_add_library(media) diff --git a/xbmc/media/MediaLockState.h b/xbmc/media/MediaLockState.h new file mode 100644 index 0000000000000..48c1183569844 --- /dev/null +++ b/xbmc/media/MediaLockState.h @@ -0,0 +1,16 @@ +/* + * 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. + */ + +#pragma once + +typedef enum +{ + LOCK_STATE_NO_LOCK = 0, + LOCK_STATE_LOCK_BUT_UNLOCKED = 1, + LOCK_STATE_LOCKED = 2, +} MediaLockState; diff --git a/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp b/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp index 3bbaf8ef38084..ccca1f37e66a7 100644 --- a/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp +++ b/xbmc/network/httprequesthandler/HTTPVfsHandler.cpp @@ -11,6 +11,7 @@ #include "URL.h" #include "Util.h" #include "filesystem/File.h" +#include "media/MediaLockState.h" #include "network/WebServer.h" #include "settings/MediaSourceSettings.h" #include "storage/MediaManager.h" @@ -52,7 +53,7 @@ CHTTPVfsHandler::CHTTPVfsHandler(const HTTPRequest &request) for (VECSOURCES::const_iterator source = sources->begin(); source != sources->end() && !accessible; ++source) { // don't allow access to locked / disabled sharing sources - if (source->m_iHasLock == 2 || !source->m_allowSharing) + if (source->m_iHasLock == LOCK_STATE_LOCKED || !source->m_allowSharing) continue; for (std::vector::const_iterator path = source->vecPaths.begin(); path != source->vecPaths.end(); ++path) @@ -74,8 +75,8 @@ CHTTPVfsHandler::CHTTPVfsHandler(const HTTPRequest &request) g_mediaManager.GetRemovableDrives(removableSources); int sourceIndex = CUtil::GetMatchingSource(realPath, removableSources, isSource); if (sourceIndex >= 0 && sourceIndex < static_cast(removableSources.size()) && - removableSources.at(sourceIndex).m_iHasLock != 2 && - removableSources.at(sourceIndex).m_allowSharing) + removableSources.at(sourceIndex).m_iHasLock != LOCK_STATE_LOCKED && + removableSources.at(sourceIndex).m_allowSharing) accessible = true; } } diff --git a/xbmc/pictures/GUIWindowPictures.cpp b/xbmc/pictures/GUIWindowPictures.cpp index a3e691878b58f..e9854f2fe91f0 100644 --- a/xbmc/pictures/GUIWindowPictures.cpp +++ b/xbmc/pictures/GUIWindowPictures.cpp @@ -24,6 +24,7 @@ #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "interfaces/AnnouncementManager.h" +#include "media/MediaLockState.h" #include "messaging/helpers/DialogOKHelper.h" #include "playlists/PlayList.h" #include "playlists/PlayListFactory.h" @@ -603,7 +604,7 @@ std::string CGUIWindowPictures::GetStartFolder(const std::string &dir) int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); if (iIndex > -1) { - if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2) + if (iIndex < static_cast(shares.size()) && shares[iIndex].m_iHasLock == LOCK_STATE_LOCKED) { CFileItem item(shares[iIndex]); if (!g_passwordManager.IsItemUnlocked(&item,"pictures")) diff --git a/xbmc/playlists/PlayListXML.cpp b/xbmc/playlists/PlayListXML.cpp index 61041ff298f7a..5876ba78b3789 100644 --- a/xbmc/playlists/PlayListXML.cpp +++ b/xbmc/playlists/PlayListXML.cpp @@ -10,6 +10,7 @@ #include "Util.h" #include "filesystem/File.h" +#include "media/MediaLockState.h" #include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/Variant.h" @@ -136,7 +137,7 @@ bool CPlayListXML::Load( const std::string& strFileName ) if ( !lockpass.empty() ) { newItem->m_strLockCode = lockpass; - newItem->m_iHasLock = 2; + newItem->m_iHasLock = LOCK_STATE_LOCKED; newItem->m_iLockMode = LOCK_MODE_NUMERIC; } @@ -181,7 +182,7 @@ void CPlayListXML::Save(const std::string& strFileName) const if ( !item->GetProperty("remotechannel").empty() ) write += StringUtils::Format(" %s", item->GetProperty("remotechannel").c_str() ); - if ( item->m_iHasLock > 0 ) + if (item->m_iHasLock > LOCK_STATE_NO_LOCK) write += StringUtils::Format(" %s", item->m_strLockCode.c_str() ); write += StringUtils::Format(" \n\n" ); diff --git a/xbmc/programs/GUIWindowPrograms.cpp b/xbmc/programs/GUIWindowPrograms.cpp index 4fff72aaeb2ff..b0894ae9a7b29 100644 --- a/xbmc/programs/GUIWindowPrograms.cpp +++ b/xbmc/programs/GUIWindowPrograms.cpp @@ -18,6 +18,7 @@ #include "guilib/GUIComponent.h" #include "guilib/GUIWindowManager.h" #include "input/Key.h" +#include "media/MediaLockState.h" #include "settings/MediaSourceSettings.h" #include "utils/StringUtils.h" @@ -158,7 +159,7 @@ std::string CGUIWindowPrograms::GetStartFolder(const std::string &dir) int iIndex = CUtil::GetMatchingSource(dir, shares, bIsSourceName); if (iIndex > -1) { - if (iIndex < (int)shares.size() && shares[iIndex].m_iHasLock == 2) + if (iIndex < static_cast(shares.size()) && shares[iIndex].m_iHasLock == LOCK_STATE_LOCKED) { CFileItem item(shares[iIndex]); if (!g_passwordManager.IsItemUnlocked(&item,"programs")) diff --git a/xbmc/settings/MediaSourceSettings.cpp b/xbmc/settings/MediaSourceSettings.cpp index 34167e2157222..84fde884481c2 100644 --- a/xbmc/settings/MediaSourceSettings.cpp +++ b/xbmc/settings/MediaSourceSettings.cpp @@ -12,6 +12,7 @@ #include "URL.h" #include "Util.h" #include "filesystem/File.h" +#include "media/MediaLockState.h" #include "network/WakeOnAccess.h" #include "profiles/ProfileManager.h" #include "settings/SettingsComponent.h" @@ -399,7 +400,7 @@ bool CMediaSourceSettings::GetSource(const std::string &category, const TiXmlNod if (pLockMode) { share.m_iLockMode = (LockType)std::strtol(pLockMode->FirstChild()->Value(), NULL, 10); - share.m_iHasLock = 2; + share.m_iHasLock = LOCK_STATE_LOCKED; } if (pLockCode && pLockCode->FirstChild()) diff --git a/xbmc/utils/FileUtils.cpp b/xbmc/utils/FileUtils.cpp index cc0455af747b6..a39f4f0f1bc52 100644 --- a/xbmc/utils/FileUtils.cpp +++ b/xbmc/utils/FileUtils.cpp @@ -20,6 +20,7 @@ #include "filesystem/StackDirectory.h" #include "guilib/GUIKeyboardFactory.h" #include "guilib/LocalizeStrings.h" +#include "media/MediaLockState.h" #include "settings/MediaSourceSettings.h" #include "settings/Settings.h" #include "settings/SettingsComponent.h" @@ -145,7 +146,9 @@ bool CFileUtils::RemoteAccessAllowed(const std::string &strPath) { VECSOURCES* sources = CMediaSourceSettings::GetInstance().GetSources(sourceName); int sourceIndex = CUtil::GetMatchingSource(realPath, *sources, isSource); - if (sourceIndex >= 0 && sourceIndex < (int)sources->size() && sources->at(sourceIndex).m_iHasLock != 2 && sources->at(sourceIndex).m_allowSharing) + if (sourceIndex >= 0 && sourceIndex < static_cast(sources->size()) && + sources->at(sourceIndex).m_iHasLock != LOCK_STATE_LOCKED && + sources->at(sourceIndex).m_allowSharing) return true; } // Check auto-mounted sources @@ -153,8 +156,9 @@ bool CFileUtils::RemoteAccessAllowed(const std::string &strPath) g_mediaManager.GetRemovableDrives(sources); // Sources returned allways have m_allowsharing = true //! @todo Make sharing of auto-mounted sources user configurable int sourceIndex = CUtil::GetMatchingSource(realPath, sources, isSource); - if (sourceIndex >= 0 && sourceIndex < static_cast(sources.size()) && - sources.at(sourceIndex).m_iHasLock != 2 && sources.at(sourceIndex).m_allowSharing) + if (sourceIndex >= 0 && sourceIndex < static_cast(sources.size()) && + sources.at(sourceIndex).m_iHasLock != LOCK_STATE_LOCKED && + sources.at(sourceIndex).m_allowSharing) return true; return false; From d884bbc5688921797cad0787b65ab5d85f218b19 Mon Sep 17 00:00:00 2001 From: howie-f Date: Fri, 21 Feb 2020 09:12:17 +0100 Subject: [PATCH 3/5] Reimplement functions for checking Master-/Medialocks --- xbmc/GUIPassword.cpp | 122 +++++++++++++++++++++++++++++-------------- xbmc/GUIPassword.h | 21 ++++++++ 2 files changed, 105 insertions(+), 38 deletions(-) diff --git a/xbmc/GUIPassword.cpp b/xbmc/GUIPassword.cpp index 37d9a8144ebcf..f5481e7b4f686 100644 --- a/xbmc/GUIPassword.cpp +++ b/xbmc/GUIPassword.cpp @@ -29,6 +29,7 @@ #include "settings/SettingsComponent.h" #include "utils/StringUtils.h" #include "utils/Variant.h" +#include "utils/log.h" #include "view/ViewStateSettings.h" #include @@ -42,41 +43,33 @@ CGUIPassword::CGUIPassword(void) } CGUIPassword::~CGUIPassword(void) = default; -bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string &strType) +template +bool CGUIPassword::IsItemUnlocked(T pItem, + const std::string& strType, + const std::string& strLabel, + const std::string& strHeading) { - const std::shared_ptr profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); - - // \brief Tests if the user is allowed to access the share folder - // \param pItem The share folder item to access - // \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() - // \return If access is granted, returns \e true + const std::shared_ptr profileManager = + CServiceBroker::GetSettingsComponent()->GetProfileManager(); if (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE) return true; while (pItem->m_iHasLock > LOCK_STATE_LOCK_BUT_UNLOCKED) { - std::string strLockCode = pItem->m_strLockCode; - std::string strLabel = pItem->GetLabel(); - int iResult = 0; // init to user succeeded state, doing this to optimize switch statement below - char buffer[33]; // holds 32 places plus sign character - if(g_passwordManager.bMasterUser)// Check if we are the MasterUser! - { - iResult = 0; - } - else + const std::string strLockCode = pItem->m_strLockCode; + int iResult = 0; // init to user succeeded state, doing this to optimize switch statement below + if (!g_passwordManager.bMasterUser) // Check if we are the MasterUser! { - if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES) && pItem->m_iBadPwdCount >= CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES)) - { // user previously exhausted all retries, show access denied error + if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + CSettings::SETTING_MASTERLOCK_MAXRETRIES) && + pItem->m_iBadPwdCount >= CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + CSettings::SETTING_MASTERLOCK_MAXRETRIES)) + { + // user previously exhausted all retries, show access denied error HELPERS::ShowOKDialogText(CVariant{12345}, CVariant{12346}); return false; } // show the appropriate lock dialog - std::string strHeading = ""; - if (pItem->m_bIsFolder) - strHeading = g_localizeStrings.Get(12325); - else - strHeading = g_localizeStrings.Get(12348); - iResult = VerifyPassword(pItem->m_iLockMode, strLockCode, strHeading); } switch (iResult) @@ -91,19 +84,20 @@ bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string &strType) // password entry succeeded pItem->m_iBadPwdCount = 0; pItem->m_iHasLock = LOCK_STATE_LOCK_BUT_UNLOCKED; - g_passwordManager.LockSource(strType,strLabel,false); - sprintf(buffer,"%i",pItem->m_iBadPwdCount); - CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount", buffer); + g_passwordManager.LockSource(strType, strLabel, false); + CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount", + std::to_string(pItem->m_iBadPwdCount)); CMediaSourceSettings::GetInstance().Save(); break; } case 1: { // password entry failed - if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES)) + if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt( + CSettings::SETTING_MASTERLOCK_MAXRETRIES)) pItem->m_iBadPwdCount++; - sprintf(buffer,"%i",pItem->m_iBadPwdCount); - CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount", buffer); + CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount", + std::to_string(pItem->m_iBadPwdCount)); CMediaSourceSettings::GetInstance().Save(); break; } @@ -118,12 +112,32 @@ bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string &strType) return true; } +bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string& strType) +{ + const std::string strLabel = pItem->GetLabel(); + std::string strHeading; + if (pItem->m_bIsFolder) + strHeading = g_localizeStrings.Get(12325); // "Locked! Enter code..." + else + strHeading = g_localizeStrings.Get(12348); // "Item locked" + + return IsItemUnlocked(pItem, strType, strLabel, strHeading); +} + +bool CGUIPassword::IsItemUnlocked(CMediaSource* pItem, const std::string& strType) +{ + const std::string strLabel = pItem->strName; + std::string strHeading = g_localizeStrings.Get(12325); // "Locked! Enter code..." + + return IsItemUnlocked(pItem, strType, strLabel, strHeading); +} + bool CGUIPassword::CheckStartUpLock() { // prompt user for mastercode if the mastercode was set b4 or by xml int iVerifyPasswordResult = -1; - std::string strHeader = g_localizeStrings.Get(20075); + std::string strHeader = g_localizeStrings.Get(20075); // "Enter master lock code" if (iMasterLockRetriesLeft == -1) iMasterLockRetriesLeft = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES); @@ -145,7 +159,7 @@ bool CGUIPassword::CheckStartUpLock() if (iVerifyPasswordResult != 0 ) { std::string strLabel1; - strLabel1 = g_localizeStrings.Get(12343); + strLabel1 = g_localizeStrings.Get(12343); // "retries left" int iLeft = g_passwordManager.iMasterLockRetriesLeft-i; std::string strLabel = StringUtils::Format("%i %s", iLeft, strLabel1.c_str()); @@ -177,6 +191,7 @@ bool CGUIPassword::SetMasterLockMode(bool bDetails) if (profile) { CProfile::CLock locks = profile->GetLocks(); + // prompt user for master lock if (CGUIDialogLockSettings::ShowAndGetLock(locks, 12360, true, bDetails)) { profile->SetLocks(locks); @@ -226,6 +241,7 @@ bool CGUIPassword::IsProfileLockUnlocked(int iProfile, bool& bCanceled, bool pro else { if (profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE) + // prompt user for profile lock code return CheckLock(profile->getLockMode(),profile->getLockCode(),20095,bCanceled); } } @@ -303,14 +319,15 @@ void CGUIPassword::UpdateMasterLockRetryCount(bool bResetCount) g_passwordManager.iMasterLockRetriesLeft = 0; // Tell the user they ran out of retry attempts HELPERS::ShowOKDialogText(CVariant{12345}, CVariant{12346}); - return ; + return; } } std::string dlgLine1 = ""; if (0 < g_passwordManager.iMasterLockRetriesLeft) - dlgLine1 = StringUtils::Format("%d %s", - g_passwordManager.iMasterLockRetriesLeft, - g_localizeStrings.Get(12343).c_str()); + dlgLine1 = StringUtils::Format("%d %s", g_passwordManager.iMasterLockRetriesLeft, + g_localizeStrings.Get(12343).c_str()); // "retries left" + + // prompt user for master lock HELPERS::ShowOKDialogLines(CVariant{20075}, CVariant{12345}, CVariant{std::move(dlgLine1)}, CVariant{0}); } else @@ -501,7 +518,9 @@ void CGUIPassword::RemoveSourceLocks() { it->m_iHasLock = LOCK_STATE_NO_LOCK; it->m_iLockMode = LOCK_MODE_EVERYONE; - CMediaSourceSettings::GetInstance().UpdateSource(strType, it->strName, "lockmode", "0"); // removes locks from xml + + // remove locks from xml + CMediaSourceSettings::GetInstance().UpdateSource(strType, it->strName, "lockmode", "0"); } } CMediaSourceSettings::GetInstance().Save(); @@ -520,13 +539,40 @@ bool CGUIPassword::IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES bool bName = false; int iIndex = CUtil::GetMatchingSource(strPath, vecSources, bName); - if (iIndex > -1 && iIndex < (int)vecSources.size()) + if (iIndex > -1 && iIndex < static_cast(vecSources.size())) if (vecSources[iIndex].m_iHasLock < LOCK_STATE_LOCKED) return true; return false; } +bool CGUIPassword::IsMediaPathUnlocked(const std::string& strPath, const std::string& strType) +{ + if (StringUtils::StartsWithNoCase(strPath, "root") || + StringUtils::StartsWithNoCase(strPath, "library://")) + { + // no mediasource-lookup needed + CLog::Log(LOGDEBUG, "CGUIPassword::IsMediaPathUnlocked - entering from {}", strPath); + return true; + } + + const std::shared_ptr profileManager = + CServiceBroker::GetSettingsComponent()->GetProfileManager(); + if (g_passwordManager.bMasterUser || + profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE) + return true; + + VECSOURCES& vecSources = *CMediaSourceSettings::GetInstance().GetSources(strType); + bool bName = false; + int iIndex = CUtil::GetMatchingSource(strPath, vecSources, bName); + if (iIndex > -1 && iIndex < static_cast(vecSources.size())) + return g_passwordManager.IsItemUnlocked(&vecSources[iIndex], strType); + + // need to add a missing filter (root/library.. etc.) + CLog::Log(LOGERROR, "CGUIPassword::IsMediaPathUnlocked - missing filter: {}", strPath); + return true; +} + void CGUIPassword::OnSettingAction(std::shared_ptr setting) { if (setting == NULL) diff --git a/xbmc/GUIPassword.h b/xbmc/GUIPassword.h index 18d0179ddeaa4..befeb83094b43 100644 --- a/xbmc/GUIPassword.h +++ b/xbmc/GUIPassword.h @@ -25,7 +25,22 @@ class CGUIPassword : public ISettingCallback public: CGUIPassword(void); ~CGUIPassword(void) override; + template + bool IsItemUnlocked(T pItem, + const std::string& strType, + const std::string& strLabel, + const std::string& strHeading); + /* \brief Tests if the user is allowed to access the share folder + \param pItem The share folder item to access + \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() + \return If access is granted, returns \e true + */ bool IsItemUnlocked(CFileItem* pItem, const std::string &strType); + /* \brief Tests if the user is allowed to access the Mediasource + \param pItem The share folder item to access + \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() + \return If access is granted, returns \e true + */ bool IsItemUnlocked(CMediaSource* pItem, const std::string &strType); bool CheckLock(LockType btnType, const std::string& strPassword, int iHeading); bool CheckLock(LockType btnType, const std::string& strPassword, int iHeading, bool& bCanceled); @@ -49,6 +64,12 @@ class CGUIPassword : public ISettingCallback void LockSources(bool lock); void RemoveSourceLocks(); bool IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES& vecSources); + /* \brief Tests if the user is allowed to access the path by looking up the matching Mediasource + \param strPath The folder path to access + \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() + \return If access is granted, returns \e true + */ + bool IsMediaPathUnlocked(const std::string& strPath, const std::string& strType); void OnSettingAction(std::shared_ptr setting) override; From 9b1855e8ba1a9d2cf1063668f2f00af4101d5d55 Mon Sep 17 00:00:00 2001 From: howie-f Date: Fri, 21 Feb 2020 09:12:17 +0100 Subject: [PATCH 4/5] Extend CheckMenuLock to check Mediasources (video and music) if needed --- xbmc/GUIPassword.cpp | 4 ++++ xbmc/GUIPassword.h | 1 + xbmc/guilib/GUIWindowManager.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/xbmc/GUIPassword.cpp b/xbmc/GUIPassword.cpp index f5481e7b4f686..07fc0b9438ea6 100644 --- a/xbmc/GUIPassword.cpp +++ b/xbmc/GUIPassword.cpp @@ -446,9 +446,13 @@ bool CGUIPassword::CheckMenuLock(int iWindowID) break; case WINDOW_MUSIC_NAV: // Music bCheckPW = profileManager->GetCurrentProfile().musicLocked(); + if (!bCheckPW && strMediasourcePath != "") // check mediasource by path + return g_passwordManager.IsMediaPathUnlocked(strMediasourcePath, "music"); break; case WINDOW_VIDEO_NAV: // Video bCheckPW = profileManager->GetCurrentProfile().videoLocked(); + if (!bCheckPW && strMediasourcePath != "") // check mediasource by path + return g_passwordManager.IsMediaPathUnlocked(strMediasourcePath, "video"); break; case WINDOW_PICTURES: // Pictures bCheckPW = profileManager->GetCurrentProfile().picturesLocked(); diff --git a/xbmc/GUIPassword.h b/xbmc/GUIPassword.h index befeb83094b43..6597da5abf013 100644 --- a/xbmc/GUIPassword.h +++ b/xbmc/GUIPassword.h @@ -75,6 +75,7 @@ class CGUIPassword : public ISettingCallback bool bMasterUser; int iMasterLockRetriesLeft; + std::string strMediasourcePath; private: int VerifyPassword(LockType btnType, const std::string& strPassword, const std::string& strHeading); diff --git a/xbmc/guilib/GUIWindowManager.cpp b/xbmc/guilib/GUIWindowManager.cpp index 3b1e63da05f82..5ac45daad1115 100644 --- a/xbmc/guilib/GUIWindowManager.cpp +++ b/xbmc/guilib/GUIWindowManager.cpp @@ -776,9 +776,18 @@ void CGUIWindowManager::ActivateWindow_Internal(int iWindowID, const std::vector // debug CLog::Log(LOGDEBUG, "Activating window ID: %i", iWindowID); + // make sure we check mediasources from home + if (GetActiveWindow() == WINDOW_HOME) + g_passwordManager.strMediasourcePath = !params.empty() ? params[0] : ""; + else + g_passwordManager.strMediasourcePath = ""; + if (!g_passwordManager.CheckMenuLock(iWindowID)) { - CLog::Log(LOGERROR, "MasterCode is Wrong: Window with id %d will not be loaded! Enter a correct MasterCode!", iWindowID); + CLog::Log(LOGERROR, + "MasterCode or Mediasource-code is wrong: Window with id {} will not be loaded! " + "Enter a correct code!", + iWindowID); if (GetActiveWindow() == WINDOW_INVALID && iWindowID != WINDOW_HOME) ActivateWindow(WINDOW_HOME); return; From 1fb63a9e1c2889f6c44a38ca1c0c605763183b5a Mon Sep 17 00:00:00 2001 From: howie-f Date: Sat, 22 Feb 2020 08:57:43 +0100 Subject: [PATCH 5/5] GUIPassword.h: fix doxygen header --- xbmc/GUIPassword.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xbmc/GUIPassword.h b/xbmc/GUIPassword.h index 6597da5abf013..94e03b032d1af 100644 --- a/xbmc/GUIPassword.h +++ b/xbmc/GUIPassword.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2018 Team Kodi + * Copyright (C) 2005-2020 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -30,13 +30,13 @@ class CGUIPassword : public ISettingCallback const std::string& strType, const std::string& strLabel, const std::string& strHeading); - /* \brief Tests if the user is allowed to access the share folder + /*! \brief Tests if the user is allowed to access the share folder \param pItem The share folder item to access \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() \return If access is granted, returns \e true */ bool IsItemUnlocked(CFileItem* pItem, const std::string &strType); - /* \brief Tests if the user is allowed to access the Mediasource + /*! \brief Tests if the user is allowed to access the Mediasource \param pItem The share folder item to access \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() \return If access is granted, returns \e true @@ -64,7 +64,7 @@ class CGUIPassword : public ISettingCallback void LockSources(bool lock); void RemoveSourceLocks(); bool IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES& vecSources); - /* \brief Tests if the user is allowed to access the path by looking up the matching Mediasource + /*! \brief Tests if the user is allowed to access the path by looking up the matching Mediasource \param strPath The folder path to access \param strType The type of share being accessed, e.g. "music", "video", etc. See CSettings::UpdateSources() \return If access is granted, returns \e true