diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 18:07:22 +0000 |
commit | c04dcc2e7d834218ef2d4194331e383402495ae1 (patch) | |
tree | 7333e38d10d75386e60f336b80c2443c1166031d /xbmc/profiles/dialogs | |
parent | Initial commit. (diff) | |
download | kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip |
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/profiles/dialogs')
-rw-r--r-- | xbmc/profiles/dialogs/CMakeLists.txt | 7 | ||||
-rw-r--r-- | xbmc/profiles/dialogs/GUIDialogLockSettings.cpp | 320 | ||||
-rw-r--r-- | xbmc/profiles/dialogs/GUIDialogLockSettings.h | 53 | ||||
-rw-r--r-- | xbmc/profiles/dialogs/GUIDialogProfileSettings.cpp | 397 | ||||
-rw-r--r-- | xbmc/profiles/dialogs/GUIDialogProfileSettings.h | 62 |
5 files changed, 839 insertions, 0 deletions
diff --git a/xbmc/profiles/dialogs/CMakeLists.txt b/xbmc/profiles/dialogs/CMakeLists.txt new file mode 100644 index 0000000..e7fc216 --- /dev/null +++ b/xbmc/profiles/dialogs/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SOURCES GUIDialogLockSettings.cpp + GUIDialogProfileSettings.cpp) + +set(HEADERS GUIDialogLockSettings.h + GUIDialogProfileSettings.h) + +core_add_library(profiles_dialogs) diff --git a/xbmc/profiles/dialogs/GUIDialogLockSettings.cpp b/xbmc/profiles/dialogs/GUIDialogLockSettings.cpp new file mode 100644 index 0000000..52eabc4 --- /dev/null +++ b/xbmc/profiles/dialogs/GUIDialogLockSettings.cpp @@ -0,0 +1,320 @@ +/* + * 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 "GUIDialogLockSettings.h" + +#include "ServiceBroker.h" +#include "URL.h" +#include "dialogs/GUIDialogGamepad.h" +#include "dialogs/GUIDialogNumeric.h" +#include "dialogs/GUIDialogSelect.h" +#include "favourites/FavouritesService.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIKeyboardFactory.h" +#include "guilib/GUIWindowManager.h" +#include "guilib/LocalizeStrings.h" +#include "settings/lib/Setting.h" +#include "settings/lib/SettingSection.h" +#include "settings/windows/GUIControlSettings.h" +#include "utils/StringUtils.h" +#include "utils/log.h" + +#include <utility> + +#define SETTING_USERNAME "user.name" +#define SETTING_PASSWORD "user.password" +#define SETTING_PASSWORD_REMEMBER "user.rememberpassword" + +#define SETTING_LOCKCODE "lock.code" +#define SETTING_LOCK_MUSIC "lock.music" +#define SETTING_LOCK_VIDEOS "lock.videos" +#define SETTING_LOCK_PICTURES "lock.pictures" +#define SETTING_LOCK_PROGRAMS "lock.programs" +#define SETTING_LOCK_FILEMANAGER "lock.filemanager" +#define SETTING_LOCK_SETTINGS "lock.settings" +#define SETTING_LOCK_ADDONMANAGER "lock.addonmanager" + +CGUIDialogLockSettings::CGUIDialogLockSettings() + : CGUIDialogSettingsManualBase(WINDOW_DIALOG_LOCK_SETTINGS, "DialogSettings.xml"), + m_saveUserDetails(NULL) +{ } + +CGUIDialogLockSettings::~CGUIDialogLockSettings() = default; + +bool CGUIDialogLockSettings::ShowAndGetLock(LockType &lockMode, std::string &password, int header /* = 20091 */) +{ + CProfile::CLock locks(lockMode, password); + if (!ShowAndGetLock(locks, header, false, false)) + return false; + + locks.Validate(); + lockMode = locks.mode; + password = locks.code; + + return true; +} + +bool CGUIDialogLockSettings::ShowAndGetLock(CProfile::CLock &locks, int buttonLabel /* = 20091 */, bool conditional /* = false */, bool details /* = true */) +{ + CGUIDialogLockSettings *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogLockSettings>(WINDOW_DIALOG_LOCK_SETTINGS); + if (dialog == NULL) + return false; + + dialog->m_locks = locks; + dialog->m_buttonLabel = buttonLabel; + dialog->m_getUser = false; + dialog->m_conditionalDetails = conditional; + dialog->m_details = details; + dialog->Open(); + + if (!dialog->m_changed) + return false; + + locks = dialog->m_locks; + + // changed lock settings for certain sections (e.g. video, audio, or pictures) + // => refresh favourites due to possible visibility changes + CServiceBroker::GetFavouritesService().RefreshFavourites(); + + return true; +} + +bool CGUIDialogLockSettings::ShowAndGetUserAndPassword(std::string &user, std::string &password, const std::string &url, bool *saveUserDetails) +{ + CGUIDialogLockSettings *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogLockSettings>(WINDOW_DIALOG_LOCK_SETTINGS); + if (dialog == NULL) + return false; + + dialog->m_getUser = true; + dialog->m_locks.code = password; + dialog->m_user = user; + dialog->m_url = url; + dialog->m_saveUserDetails = saveUserDetails; + dialog->Open(); + + if (!dialog->m_changed) + return false; + + user = dialog->m_user; + password = dialog->m_locks.code; + return true; +} + +void CGUIDialogLockSettings::OnSettingChanged(const std::shared_ptr<const CSetting>& setting) +{ + if (setting == NULL) + return; + + CGUIDialogSettingsManualBase::OnSettingChanged(setting); + + const std::string &settingId = setting->GetId(); + if (settingId == SETTING_USERNAME) + m_user = std::static_pointer_cast<const CSettingString>(setting)->GetValue(); + else if (settingId == SETTING_PASSWORD) + m_locks.code = std::static_pointer_cast<const CSettingString>(setting)->GetValue(); + else if (settingId == SETTING_PASSWORD_REMEMBER) + *m_saveUserDetails = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_MUSIC) + m_locks.music = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_VIDEOS) + m_locks.video = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_PICTURES) + m_locks.pictures = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_PROGRAMS) + m_locks.programs = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_FILEMANAGER) + m_locks.files = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + else if (settingId == SETTING_LOCK_SETTINGS) + m_locks.settings = static_cast<LOCK_LEVEL::SETTINGS_LOCK>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue()); + else if (settingId == SETTING_LOCK_ADDONMANAGER) + m_locks.addonManager = std::static_pointer_cast<const CSettingBool>(setting)->GetValue(); + + m_changed = true; +} + +void CGUIDialogLockSettings::OnSettingAction(const std::shared_ptr<const CSetting>& setting) +{ + if (setting == NULL) + return; + + CGUIDialogSettingsManualBase::OnSettingAction(setting); + + const std::string &settingId = setting->GetId(); + if (settingId == SETTING_LOCKCODE) + { + CGUIDialogSelect* dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>(WINDOW_DIALOG_SELECT); + if (!dialog) + return; + + dialog->Reset(); + dialog->SetHeading(CVariant{12360}); + dialog->Add(g_localizeStrings.Get(1223)); + dialog->Add(g_localizeStrings.Get(12337)); + dialog->Add(g_localizeStrings.Get(12338)); + dialog->Add(g_localizeStrings.Get(12339)); + dialog->SetSelected(GetLockModeLabel()); + dialog->Open(); + + std::string newPassword; + LockType iLockMode = LOCK_MODE_UNKNOWN; + bool bResult = false; + switch (dialog->GetSelectedItem()) + { + case 0: + iLockMode = LOCK_MODE_EVERYONE; //Disabled! Need check routine!!! + bResult = true; + break; + + case 1: + iLockMode = LOCK_MODE_NUMERIC; + bResult = CGUIDialogNumeric::ShowAndVerifyNewPassword(newPassword); + break; + + case 2: + iLockMode = LOCK_MODE_GAMEPAD; + bResult = CGUIDialogGamepad::ShowAndVerifyNewPassword(newPassword); + break; + + case 3: + iLockMode = LOCK_MODE_QWERTY; + bResult = CGUIKeyboardFactory::ShowAndVerifyNewPassword(newPassword); + break; + + default: + break; + } + + if (bResult) + { + if (iLockMode == LOCK_MODE_EVERYONE) + newPassword = "-"; + m_locks.code = newPassword; + if (m_locks.code == "-") + iLockMode = LOCK_MODE_EVERYONE; + m_locks.mode = iLockMode; + + SetSettingLockCodeLabel(); + SetDetailSettingsEnabled(m_locks.mode != LOCK_MODE_EVERYONE); + m_changed = true; + } + } +} + +void CGUIDialogLockSettings::OnCancel() +{ + m_changed = false; + + CGUIDialogSettingsManualBase::OnCancel(); +} + +void CGUIDialogLockSettings::SetupView() +{ + CGUIDialogSettingsManualBase::SetupView(); + + // set the title + if (m_getUser) + SetHeading(StringUtils::Format(g_localizeStrings.Get(20152), CURL::Decode(m_url))); + else + { + SetHeading(20066); + SetSettingLockCodeLabel(); + SetDetailSettingsEnabled(m_locks.mode != LOCK_MODE_EVERYONE); + } + SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON); + SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON, 186); + SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON, 222); +} + +void CGUIDialogLockSettings::InitializeSettings() +{ + CGUIDialogSettingsManualBase::InitializeSettings(); + + const std::shared_ptr<CSettingCategory> category = AddCategory("locksettings", -1); + if (category == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogLockSettings: unable to setup settings"); + return; + } + + const std::shared_ptr<CSettingGroup> group = AddGroup(category); + if (group == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogLockSettings: unable to setup settings"); + return; + } + + if (m_getUser) + { + AddEdit(group, SETTING_USERNAME, 20142, SettingLevel::Basic, m_user); + AddEdit(group, SETTING_PASSWORD, 12326, SettingLevel::Basic, m_locks.code, false, true); + if (m_saveUserDetails != NULL) + AddToggle(group, SETTING_PASSWORD_REMEMBER, 13423, SettingLevel::Basic, *m_saveUserDetails); + + return; + } + + AddButton(group, SETTING_LOCKCODE, m_buttonLabel, SettingLevel::Basic); + + if (m_details) + { + const std::shared_ptr<CSettingGroup> groupDetails = AddGroup(category); + if (groupDetails == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogLockSettings: unable to setup settings"); + return; + } + + AddToggle(groupDetails, SETTING_LOCK_MUSIC, 20038, SettingLevel::Basic, m_locks.music); + AddToggle(groupDetails, SETTING_LOCK_VIDEOS, 20039, SettingLevel::Basic, m_locks.video); + AddToggle(groupDetails, SETTING_LOCK_PICTURES, 20040, SettingLevel::Basic, m_locks.pictures); + AddToggle(groupDetails, SETTING_LOCK_PROGRAMS, 20041, SettingLevel::Basic, m_locks.programs); + AddToggle(groupDetails, SETTING_LOCK_FILEMANAGER, 20042, SettingLevel::Basic, m_locks.files); + + TranslatableIntegerSettingOptions settingsLevelOptions; + settingsLevelOptions.push_back(TranslatableIntegerSettingOption(106, LOCK_LEVEL::NONE)); + settingsLevelOptions.push_back(TranslatableIntegerSettingOption(593, LOCK_LEVEL::ALL)); + settingsLevelOptions.push_back(TranslatableIntegerSettingOption(10037, LOCK_LEVEL::STANDARD)); + settingsLevelOptions.push_back(TranslatableIntegerSettingOption(10038, LOCK_LEVEL::ADVANCED)); + settingsLevelOptions.push_back(TranslatableIntegerSettingOption(10039, LOCK_LEVEL::EXPERT)); + AddList(groupDetails, SETTING_LOCK_SETTINGS, 20043, SettingLevel::Basic, static_cast<int>(m_locks.settings), settingsLevelOptions, 20043); + + AddToggle(groupDetails, SETTING_LOCK_ADDONMANAGER, 24090, SettingLevel::Basic, m_locks.addonManager); + } + + m_changed = false; +} + +std::string CGUIDialogLockSettings::GetLockModeLabel() +{ + return g_localizeStrings.Get(m_locks.mode == LOCK_MODE_EVERYONE ? 1223 : 12336 + m_locks.mode); +} + +void CGUIDialogLockSettings::SetDetailSettingsEnabled(bool enabled) +{ + if (!m_details) + return; + + enabled |= !m_conditionalDetails; + GetSettingControl(SETTING_LOCK_MUSIC)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_VIDEOS)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_PICTURES)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_PROGRAMS)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_FILEMANAGER)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_SETTINGS)->GetSetting()->SetEnabled(enabled); + GetSettingControl(SETTING_LOCK_ADDONMANAGER)->GetSetting()->SetEnabled(enabled); +} + +void CGUIDialogLockSettings::SetSettingLockCodeLabel() +{ + // adjust label2 of the lock code setting button + if (m_locks.mode > LOCK_MODE_QWERTY) + m_locks.mode = LOCK_MODE_EVERYONE; + BaseSettingControlPtr settingControl = GetSettingControl(SETTING_LOCKCODE); + if (settingControl != NULL && settingControl->GetControl() != NULL) + SET_CONTROL_LABEL2(settingControl->GetID(), GetLockModeLabel()); +} diff --git a/xbmc/profiles/dialogs/GUIDialogLockSettings.h b/xbmc/profiles/dialogs/GUIDialogLockSettings.h new file mode 100644 index 0000000..bdcaed7 --- /dev/null +++ b/xbmc/profiles/dialogs/GUIDialogLockSettings.h @@ -0,0 +1,53 @@ +/* + * 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 "profiles/Profile.h" +#include "settings/dialogs/GUIDialogSettingsManualBase.h" + +class CGUIDialogLockSettings : public CGUIDialogSettingsManualBase +{ +public: + CGUIDialogLockSettings(); + ~CGUIDialogLockSettings() override; + + static bool ShowAndGetLock(LockType &lockMode, std::string &password, int header = 20091); + static bool ShowAndGetLock(CProfile::CLock &locks, int buttonLabel = 20091, bool conditional = false, bool details = true); + static bool ShowAndGetUserAndPassword(std::string &user, std::string &password, const std::string &url, bool *saveUserDetails); + +protected: + // implementations of ISettingCallback + void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override; + void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override; + + // specialization of CGUIDialogSettingsBase + bool AllowResettingSettings() const override { return false; } + bool Save() override { return true; } + void OnCancel() override; + void SetupView() override; + + // specialization of CGUIDialogSettingsManualBase + void InitializeSettings() override; + +private: + std::string GetLockModeLabel(); + void SetDetailSettingsEnabled(bool enabled); + void SetSettingLockCodeLabel(); + + bool m_changed = false; + + CProfile::CLock m_locks; + std::string m_user; + std::string m_url; + bool m_details = true; + bool m_conditionalDetails = false; + bool m_getUser = false; + bool* m_saveUserDetails; + int m_buttonLabel = 20091; +}; diff --git a/xbmc/profiles/dialogs/GUIDialogProfileSettings.cpp b/xbmc/profiles/dialogs/GUIDialogProfileSettings.cpp new file mode 100644 index 0000000..d7ce0da --- /dev/null +++ b/xbmc/profiles/dialogs/GUIDialogProfileSettings.cpp @@ -0,0 +1,397 @@ +/* + * 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 "GUIDialogProfileSettings.h" + +#include "FileItem.h" +#include "GUIPassword.h" +#include "ServiceBroker.h" +#include "Util.h" +#include "dialogs/GUIDialogFileBrowser.h" +#include "dialogs/GUIDialogYesNo.h" +#include "filesystem/Directory.h" +#include "filesystem/File.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIKeyboardFactory.h" +#include "guilib/GUIWindowManager.h" +#include "guilib/LocalizeStrings.h" +#include "profiles/ProfileManager.h" +#include "profiles/dialogs/GUIDialogLockSettings.h" +#include "settings/SettingsComponent.h" +#include "settings/lib/Setting.h" +#include "settings/windows/GUIControlSettings.h" +#include "storage/MediaManager.h" +#include "utils/StringUtils.h" +#include "utils/URIUtils.h" +#include "utils/Variant.h" +#include "utils/log.h" + +#include <cassert> +#include <utility> + +#define SETTING_PROFILE_NAME "profile.name" +#define SETTING_PROFILE_IMAGE "profile.image" +#define SETTING_PROFILE_DIRECTORY "profile.directory" +#define SETTING_PROFILE_LOCKS "profile.locks" +#define SETTING_PROFILE_MEDIA "profile.media" +#define SETTING_PROFILE_MEDIA_SOURCES "profile.mediasources" + +CGUIDialogProfileSettings::CGUIDialogProfileSettings() + : CGUIDialogSettingsManualBase(WINDOW_DIALOG_PROFILE_SETTINGS, "DialogSettings.xml") +{ } + +CGUIDialogProfileSettings::~CGUIDialogProfileSettings() = default; + +bool CGUIDialogProfileSettings::ShowForProfile(unsigned int iProfile, bool firstLogin) +{ + const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); + + if (firstLogin && iProfile > profileManager->GetNumberOfProfiles()) + return false; + + CGUIDialogProfileSettings *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogProfileSettings>(WINDOW_DIALOG_PROFILE_SETTINGS); + if (dialog == NULL) + return false; + + dialog->m_needsSaving = false; + dialog->m_isDefault = iProfile == 0; + dialog->m_showDetails = !firstLogin; + + const CProfile *profile = profileManager->GetProfile(iProfile); + if (profile == NULL) + { + dialog->m_name.clear(); + dialog->m_dbMode = 2; + dialog->m_sourcesMode = 2; + dialog->m_locks = CProfile::CLock(); + + bool bLock = profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE && !g_passwordManager.bMasterUser; + dialog->m_locks.addonManager = bLock; + dialog->m_locks.settings = (bLock) ? LOCK_LEVEL::ALL : LOCK_LEVEL::NONE; + dialog->m_locks.files = bLock; + + dialog->m_directory.clear(); + dialog->m_thumb.clear(); + + // prompt for a name + std::string profileName; + if (!CGUIKeyboardFactory::ShowAndGetInput(profileName, CVariant{g_localizeStrings.Get(20093)}, false) || profileName.empty()) + return false; + dialog->m_name = profileName; + + // create a default path + std::string defaultDir = URIUtils::AddFileToFolder("profiles", CUtil::MakeLegalFileName(dialog->m_name)); + URIUtils::AddSlashAtEnd(defaultDir); + XFILE::CDirectory::Create(URIUtils::AddFileToFolder("special://masterprofile/", defaultDir)); + + // prompt for the user to change it if they want + std::string userDir = defaultDir; + if (GetProfilePath(userDir, false)) // can't be the master user + { + if (!URIUtils::PathHasParent(userDir, defaultDir)) // user chose a different folder + XFILE::CDirectory::Remove(URIUtils::AddFileToFolder("special://masterprofile/", defaultDir)); + } + dialog->m_directory = userDir; + dialog->m_needsSaving = true; + } + else + { + dialog->m_name = profile->getName(); + dialog->m_thumb = profile->getThumb(); + dialog->m_directory = profile->getDirectory(); + dialog->m_dbMode = profile->canWriteDatabases() ? 0 : 1; + if (profile->hasDatabases()) + dialog->m_dbMode += 2; + dialog->m_sourcesMode = profile->canWriteSources() ? 0 : 1; + if (profile->hasSources()) + dialog->m_sourcesMode += 2; + + dialog->m_locks = profile->GetLocks(); + } + + dialog->Open(); + if (dialog->m_needsSaving) + { + if (iProfile >= profileManager->GetNumberOfProfiles()) + { + if (dialog->m_name.empty() || dialog->m_directory.empty()) + return false; + + /*std::string strLabel; + strLabel.Format(g_localizeStrings.Get(20047),dialog->m_strName); + if (!CGUIDialogYesNo::ShowAndGetInput(20058, strLabel, dialog->m_strDirectory, "")) + { + CDirectory::Remove(URIUtils::AddFileToFolder(profileManager.GetUserDataFolder(), dialog->m_strDirectory)); + return false; + }*/ + + // check for old profile settings + CProfile profile(dialog->m_directory, dialog->m_name, profileManager->GetNextProfileId()); + profileManager->AddProfile(profile); + bool exists = XFILE::CFile::Exists(URIUtils::AddFileToFolder("special://masterprofile/", dialog->m_directory, "guisettings.xml")); + + if (exists && !CGUIDialogYesNo::ShowAndGetInput(CVariant{20058}, CVariant{20104})) + exists = false; + + if (!exists) + { + // copy masterprofile guisettings to new profile guisettings + // If the user selects 'start fresh', do nothing as a fresh + // guisettings.xml will be created on first profile use. + if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20058}, CVariant{20048}, CVariant{""}, CVariant{""}, CVariant{20044}, CVariant{20064})) + { + XFILE::CFile::Copy(URIUtils::AddFileToFolder("special://masterprofile/", "guisettings.xml"), + URIUtils::AddFileToFolder("special://masterprofile/", dialog->m_directory, "guisettings.xml")); + } + } + + exists = XFILE::CFile::Exists(URIUtils::AddFileToFolder("special://masterprofile/", dialog->m_directory, "sources.xml")); + if (exists && !CGUIDialogYesNo::ShowAndGetInput(CVariant{20058}, CVariant{20106})) + exists = false; + + if (!exists) + { + if ((dialog->m_sourcesMode & 2) == 2) + // prompt user to copy masterprofile's sources.xml file + // If 'start fresh' (no) is selected, do nothing. + if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20058}, CVariant{20071}, CVariant{""}, CVariant{""}, CVariant{20044}, CVariant{20064})) + { + XFILE::CFile::Copy(URIUtils::AddFileToFolder("special://masterprofile/", "sources.xml"), + URIUtils::AddFileToFolder("special://masterprofile/", dialog->m_directory, "sources.xml")); + } + } + } + + /*if (!dialog->m_bIsNewUser) + if (!CGUIDialogYesNo::ShowAndGetInput(20067, 20103)) + return false;*/ + + CProfile *profile = profileManager->GetProfile(iProfile); + assert(profile); + profile->setName(dialog->m_name); + profile->setDirectory(dialog->m_directory); + profile->setThumb(dialog->m_thumb); + profile->setWriteDatabases(!((dialog->m_dbMode & 1) == 1)); + profile->setWriteSources(!((dialog->m_sourcesMode & 1) == 1)); + profile->setDatabases((dialog->m_dbMode & 2) == 2); + profile->setSources((dialog->m_sourcesMode & 2) == 2); + profile->SetLocks(dialog->m_locks); + profileManager->Save(); + + return true; + } + + return dialog->m_needsSaving; +} + +void CGUIDialogProfileSettings::OnWindowLoaded() +{ + CGUIDialogSettingsManualBase::OnWindowLoaded(); +} + +void CGUIDialogProfileSettings::OnSettingChanged(const std::shared_ptr<const CSetting>& setting) +{ + if (setting == NULL) + return; + + CGUIDialogSettingsManualBase::OnSettingChanged(setting); + + const std::string &settingId = setting->GetId(); + if (settingId == SETTING_PROFILE_NAME) + { + m_name = std::static_pointer_cast<const CSettingString>(setting)->GetValue(); + } + else if (settingId == SETTING_PROFILE_MEDIA) + m_dbMode = std::static_pointer_cast<const CSettingInt>(setting)->GetValue(); + else if (settingId == SETTING_PROFILE_MEDIA_SOURCES) + m_sourcesMode = std::static_pointer_cast<const CSettingInt>(setting)->GetValue(); + + m_needsSaving = true; +} + +void CGUIDialogProfileSettings::OnSettingAction(const std::shared_ptr<const CSetting>& setting) +{ + if (setting == NULL) + return; + + CGUIDialogSettingsManualBase::OnSettingAction(setting); + + const std::string &settingId = setting->GetId(); + if (settingId == SETTING_PROFILE_IMAGE) + { + VECSOURCES shares; + CServiceBroker::GetMediaManager().GetLocalDrives(shares); + + CFileItemList items; + if (!m_thumb.empty()) + { + CFileItemPtr item(new CFileItem("thumb://Current", false)); + item->SetArt("thumb", m_thumb); + item->SetLabel(g_localizeStrings.Get(20016)); + items.Add(item); + } + + CFileItemPtr item(new CFileItem("thumb://None", false)); + item->SetArt("thumb", "DefaultUser.png"); + item->SetLabel(g_localizeStrings.Get(20018)); + items.Add(item); + + std::string thumb; + if (CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), thumb) && + !StringUtils::EqualsNoCase(thumb, "thumb://Current")) + { + m_needsSaving = true; + m_thumb = StringUtils::EqualsNoCase(thumb, "thumb://None") ? "" : thumb; + + UpdateProfileImage(); + } + } + else if (settingId == SETTING_PROFILE_DIRECTORY) + { + if (!GetProfilePath(m_directory, m_isDefault)) + return; + + m_needsSaving = true; + updateProfileDirectory(); + } + else if (settingId == SETTING_PROFILE_LOCKS) + { + if (m_showDetails) + { + const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); + + if (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE && !m_isDefault) + { + if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20066}, CVariant{20118})) + g_passwordManager.SetMasterLockMode(false); + if (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE) + return; + } + if (CGUIDialogLockSettings::ShowAndGetLock(m_locks, m_isDefault ? 12360 : 20068, + profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE || m_isDefault)) + m_needsSaving = true; + } + else + { + if (CGUIDialogLockSettings::ShowAndGetLock(m_locks, m_isDefault ? 12360 : 20068, false, false)) + m_needsSaving = true; + } + } +} + +void CGUIDialogProfileSettings::OnCancel() +{ + m_needsSaving = false; + + CGUIDialogSettingsManualBase::OnCancel(); +} + +void CGUIDialogProfileSettings::SetupView() +{ + CGUIDialogSettingsManualBase::SetupView(); + + // set the heading + SetHeading(!m_showDetails ? 20255 : 20067); + + SET_CONTROL_HIDDEN(CONTROL_SETTINGS_CUSTOM_BUTTON); + SET_CONTROL_LABEL(CONTROL_SETTINGS_OKAY_BUTTON, 186); + SET_CONTROL_LABEL(CONTROL_SETTINGS_CANCEL_BUTTON, 222); + + // set the profile image and directory + UpdateProfileImage(); + updateProfileDirectory(); +} + +void CGUIDialogProfileSettings::InitializeSettings() +{ + CGUIDialogSettingsManualBase::InitializeSettings(); + + const std::shared_ptr<CSettingCategory> category = AddCategory("profilesettings", -1); + if (category == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogProfileSettings: unable to setup settings"); + return; + } + + const std::shared_ptr<CSettingGroup> group = AddGroup(category); + if (group == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogProfileSettings: unable to setup settings"); + return; + } + + const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); + + AddEdit(group, SETTING_PROFILE_NAME, 20093, SettingLevel::Basic, m_name); + AddButton(group, SETTING_PROFILE_IMAGE, 20065, SettingLevel::Basic); + + if (!m_isDefault && m_showDetails) + AddButton(group, SETTING_PROFILE_DIRECTORY, 20070, SettingLevel::Basic); + + if (m_showDetails || + (m_locks.mode == LOCK_MODE_EVERYONE && profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)) + AddButton(group, SETTING_PROFILE_LOCKS, 20066, SettingLevel::Basic); + + if (!m_isDefault && m_showDetails) + { + const std::shared_ptr<CSettingGroup> groupMedia = AddGroup(category); + if (groupMedia == NULL) + { + CLog::Log(LOGERROR, "CGUIDialogProfileSettings: unable to setup settings"); + return; + } + + TranslatableIntegerSettingOptions entries; + entries.push_back(TranslatableIntegerSettingOption(20062, 0)); + entries.push_back(TranslatableIntegerSettingOption(20063, 1)); + entries.push_back(TranslatableIntegerSettingOption(20061, 2)); + if (profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE) + entries.push_back(TranslatableIntegerSettingOption(20107, 3)); + + AddSpinner(groupMedia, SETTING_PROFILE_MEDIA, 20060, SettingLevel::Basic, m_dbMode, entries); + AddSpinner(groupMedia, SETTING_PROFILE_MEDIA_SOURCES, 20094, SettingLevel::Basic, m_sourcesMode, entries); + } +} + +bool CGUIDialogProfileSettings::GetProfilePath(std::string &directory, bool isDefault) +{ + VECSOURCES shares; + CMediaSource share; + share.strName = g_localizeStrings.Get(13200); + share.strPath = "special://masterprofile/profiles/"; + shares.push_back(share); + + std::string strDirectory; + if (directory.empty()) + strDirectory = share.strPath; + else + strDirectory = URIUtils::AddFileToFolder("special://masterprofile/", directory); + + if (!CGUIDialogFileBrowser::ShowAndGetDirectory(shares, g_localizeStrings.Get(657), strDirectory, true)) + return false; + + directory = strDirectory; + if (!isDefault) + directory.erase(0, 24); + + return true; +} + +void CGUIDialogProfileSettings::UpdateProfileImage() +{ + BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROFILE_IMAGE); + if (settingControl != NULL && settingControl->GetControl() != NULL) + SET_CONTROL_LABEL2(settingControl->GetID(), URIUtils::GetFileName(m_thumb)); +} + +void CGUIDialogProfileSettings::updateProfileDirectory() +{ + BaseSettingControlPtr settingControl = GetSettingControl(SETTING_PROFILE_DIRECTORY); + if (settingControl != NULL && settingControl->GetControl() != NULL) + SET_CONTROL_LABEL2(settingControl->GetID(), m_directory); +} diff --git a/xbmc/profiles/dialogs/GUIDialogProfileSettings.h b/xbmc/profiles/dialogs/GUIDialogProfileSettings.h new file mode 100644 index 0000000..5b6f14e --- /dev/null +++ b/xbmc/profiles/dialogs/GUIDialogProfileSettings.h @@ -0,0 +1,62 @@ +/* + * 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 "profiles/Profile.h" +#include "settings/dialogs/GUIDialogSettingsManualBase.h" + +#include <string> + +class CGUIDialogProfileSettings : public CGUIDialogSettingsManualBase +{ +public: + CGUIDialogProfileSettings(); + ~CGUIDialogProfileSettings() override; + + static bool ShowForProfile(unsigned int iProfile, bool firstLogin = false); + +protected: + // specializations of CGUIWindow + void OnWindowLoaded() override; + + // implementations of ISettingCallback + void OnSettingChanged(const std::shared_ptr<const CSetting>& setting) override; + void OnSettingAction(const std::shared_ptr<const CSetting>& setting) override; + + // specialization of CGUIDialogSettingsBase + bool AllowResettingSettings() const override { return false; } + bool Save() override { return true; } + void OnCancel() override; + void SetupView() override; + + // specialization of CGUIDialogSettingsManualBase + void InitializeSettings() override; + + /*! \brief Prompt for a change in profile path + \param directory Current directory for the profile, new profile directory will be returned here + \param isDefault whether this is the default profile or not + \return true if the profile path has been changed, false otherwise. + */ + static bool GetProfilePath(std::string &directory, bool isDefault); + + void UpdateProfileImage(); + void updateProfileDirectory(); + + bool m_needsSaving = false; + std::string m_name; + std::string m_thumb; + std::string m_directory; + int m_sourcesMode; + int m_dbMode; + bool m_isDefault; + bool m_isNewUser; + bool m_showDetails; + + CProfile::CLock m_locks; +}; |