-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Dialogs for direct Audiostream and Subtitle switching #16825
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,8 @@ | |
#include "dialogs/GUIDialogPlayEject.h" | ||
#include "dialogs/GUIDialogMediaFilter.h" | ||
#include "video/dialogs/GUIDialogSubtitles.h" | ||
#include "video/dialogs/GUIDialogSubtitleSelect.h" | ||
#include "video/dialogs/GUIDialogAudioSelect.h" | ||
|
||
#include "peripherals/dialogs/GUIDialogPeripherals.h" | ||
#include "peripherals/dialogs/GUIDialogPeripheralSettings.h" | ||
|
@@ -241,6 +243,8 @@ void CGUIWindowManager::CreateWindows() | |
|
||
Add(new CGUIDialogMediaFilter); | ||
Add(new CGUIDialogSubtitles); | ||
Add(new CGUIDialogSubtitleSelect); | ||
Add(new CGUIDialogAudioSelect); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Destruction of the new dialog instances in |
||
|
||
Add(new CGUIWindowMusicPlayList); | ||
Add(new CGUIWindowMusicNav); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright (C) 2005-2019 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 "GUIDialogAudioSelect.h" | ||
|
||
#include "Application.h" | ||
#include "GUIUserMessages.h" | ||
#include "LangInfo.h" | ||
#include "ServiceBroker.h" | ||
#include "URL.h" | ||
#include "Util.h" | ||
#include "addons/AddonManager.h" | ||
#include "cores/IPlayer.h" | ||
#include "dialogs/GUIDialogKaiToast.h" | ||
#include "dialogs/GUIDialogSelect.h" | ||
#include "filesystem/AddonsDirectory.h" | ||
#include "filesystem/Directory.h" | ||
#include "filesystem/File.h" | ||
#include "filesystem/SpecialProtocol.h" | ||
#include "filesystem/StackDirectory.h" | ||
#include "guilib/GUIComponent.h" | ||
#include "guilib/GUIKeyboardFactory.h" | ||
#include "guilib/GUIWindowManager.h" | ||
#include "guilib/LocalizeStrings.h" | ||
#include "input/Key.h" | ||
#include "settings/Settings.h" | ||
#include "settings/lib/Setting.h" | ||
#include "utils/JobManager.h" | ||
#include "utils/LangCodeExpander.h" | ||
#include "utils/StringUtils.h" | ||
#include "utils/URIUtils.h" | ||
#include "utils/Variant.h" | ||
#include "utils/log.h" | ||
#include "video/VideoDatabase.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt that all these headers are actually needed. Example: |
||
|
||
#include "system.h" | ||
|
||
using namespace ADDON; | ||
using namespace XFILE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this using statements. |
||
|
||
#define STRING_AUDIO_HEADER 460 | ||
#define STRING_TOAST_TEXT_ERROR 416 | ||
|
||
CGUIDialogAudioSelect::CGUIDialogAudioSelect(void) : CGUIDialog(WINDOW_DIALOG_AUDIO_SELECT, "") | ||
{ | ||
m_loadType = KEEP_IN_MEMORY; | ||
} | ||
|
||
CGUIDialogAudioSelect::~CGUIDialogAudioSelect(void) | ||
{ | ||
} | ||
|
||
bool CGUIDialogAudioSelect::OnMessage(CGUIMessage& message) | ||
{ | ||
return CGUIDialog::OnMessage(message); | ||
} | ||
|
||
void CGUIDialogAudioSelect::OnInitWindow() | ||
{ | ||
ShowAudioSelect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure it is correct to show the dialog in |
||
|
||
CGUIWindow::OnInitWindow(); | ||
} | ||
|
||
bool CGUIDialogAudioSelect::ShowAudioSelect() | ||
{ | ||
//Only display when playing | ||
if (!g_application.GetAppPlayer().HasPlayer()) | ||
{ | ||
CGUIDialogKaiToast::QueueNotification( | ||
CGUIDialogKaiToast::Info, g_localizeStrings.Get(STRING_AUDIO_HEADER), | ||
g_localizeStrings.Get(STRING_TOAST_TEXT_ERROR), TOAST_DISPLAY_TIME, false); | ||
return false; | ||
} | ||
|
||
CGUIDialogSelect* dialog = | ||
CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( | ||
WINDOW_DIALOG_SELECT); | ||
if (dialog == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return false; | ||
|
||
CFileItemList options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would define vars where they are actually first used. |
||
|
||
int audioStreamCount = g_application.GetAppPlayer().GetAudioStreamCount(); | ||
int currentAudio = g_application.GetAppPlayer().GetAudioStream(); | ||
|
||
// cycle through each subtitle and add it to our entry list | ||
for (int i = 0; i < audioStreamCount; ++i) | ||
{ | ||
std::string strItem; | ||
std::string strLanguage; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would define vars where they are actually first used. |
||
|
||
AudioStreamInfo info; | ||
g_application.GetAppPlayer().GetAudioStreamInfo(i, info); | ||
|
||
if (!g_LangCodeExpander.Lookup(info.language, strLanguage)) | ||
strLanguage = g_localizeStrings.Get(13205); // Unknown | ||
|
||
if (info.name.length() == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
strItem = strLanguage; | ||
else | ||
strItem = StringUtils::Format("%s - %s", strLanguage.c_str(), info.name.c_str()); | ||
|
||
CFileItemPtr item(new CFileItem(strItem.c_str())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
item->SetProperty("value", i); | ||
|
||
if (i == currentAudio) | ||
item->Select(true); | ||
|
||
options.Add(item); | ||
} | ||
|
||
if (options.Size() < 2) | ||
{ | ||
CGUIDialogKaiToast::QueueNotification( | ||
CGUIDialogKaiToast::Info, g_localizeStrings.Get(STRING_AUDIO_HEADER), | ||
g_localizeStrings.Get(STRING_TOAST_TEXT_ERROR), TOAST_DISPLAY_TIME, false); | ||
return true; | ||
} | ||
|
||
dialog->Reset(); | ||
dialog->SetHeading(g_localizeStrings.Get(STRING_AUDIO_HEADER).c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
dialog->SetItems(options); | ||
dialog->SetMultiSelection(false); | ||
dialog->Open(); | ||
|
||
if (!dialog->IsConfirmed()) | ||
return true; | ||
|
||
int selected = dialog->GetSelectedItem(); | ||
if (selected != currentAudio) | ||
{ | ||
g_application.GetAppPlayer().SetAudioStream(selected); | ||
} | ||
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
/* | ||
* Copyright (C) 2005-2019 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 "guilib/GUIDialog.h" | ||
|
||
#include <string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include not needed. |
||
|
||
class CFileItem; | ||
class CFileItemList; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These forward decls are not needed. |
||
|
||
class CGUIDialogAudioSelect : public CGUIDialog | ||
{ | ||
public: | ||
CGUIDialogAudioSelect(void); | ||
~CGUIDialogAudioSelect(void) override; | ||
bool OnMessage(CGUIMessage& message) override; | ||
void OnInitWindow() override; | ||
|
||
protected: | ||
bool ShowAudioSelect(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright (C) 2005-2019 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 "GUIDialogSubtitleSelect.h" | ||
|
||
#include "Application.h" | ||
#include "GUIUserMessages.h" | ||
#include "LangInfo.h" | ||
#include "ServiceBroker.h" | ||
#include "URL.h" | ||
#include "Util.h" | ||
#include "addons/AddonManager.h" | ||
#include "cores/IPlayer.h" | ||
#include "dialogs/GUIDialogKaiToast.h" | ||
#include "dialogs/GUIDialogSelect.h" | ||
#include "filesystem/AddonsDirectory.h" | ||
#include "filesystem/Directory.h" | ||
#include "filesystem/File.h" | ||
#include "filesystem/SpecialProtocol.h" | ||
#include "filesystem/StackDirectory.h" | ||
#include "guilib/GUIComponent.h" | ||
#include "guilib/GUIKeyboardFactory.h" | ||
#include "guilib/GUIWindowManager.h" | ||
#include "guilib/LocalizeStrings.h" | ||
#include "input/Key.h" | ||
#include "settings/Settings.h" | ||
#include "settings/lib/Setting.h" | ||
#include "utils/JobManager.h" | ||
#include "utils/LangCodeExpander.h" | ||
#include "utils/StringUtils.h" | ||
#include "utils/URIUtils.h" | ||
#include "utils/Variant.h" | ||
#include "utils/log.h" | ||
#include "video/VideoDatabase.h" | ||
|
||
#include "system.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt that all these headers are actually needed. Example: |
||
|
||
using namespace ADDON; | ||
using namespace XFILE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need this using statements. |
||
|
||
#define STRING_SUBTITLES_HEADER 287 | ||
#define STRING_TOAST_TEXT_ERROR 24109 | ||
|
||
CGUIDialogSubtitleSelect::CGUIDialogSubtitleSelect(void) | ||
: CGUIDialog(WINDOW_DIALOG_SUBTITLE_SELECT, "") | ||
{ | ||
m_loadType = KEEP_IN_MEMORY; | ||
} | ||
|
||
CGUIDialogSubtitleSelect::~CGUIDialogSubtitleSelect(void) | ||
{ | ||
} | ||
|
||
bool CGUIDialogSubtitleSelect::OnMessage(CGUIMessage& message) | ||
{ | ||
return CGUIDialog::OnMessage(message); | ||
} | ||
|
||
void CGUIDialogSubtitleSelect::OnInitWindow() | ||
{ | ||
ShowSubtitleSelect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure it is correct to show the dialog in OnInitWindow - while the dialog is not yet fully initialized? Did you copy this pattern from an existing dialog implementation? |
||
|
||
CGUIWindow::OnInitWindow(); | ||
} | ||
|
||
bool CGUIDialogSubtitleSelect::ShowSubtitleSelect() | ||
{ | ||
//Only display when playing | ||
if (!g_application.GetAppPlayer().HasPlayer()) | ||
{ | ||
CGUIDialogKaiToast::QueueNotification( | ||
CGUIDialogKaiToast::Info, g_localizeStrings.Get(STRING_SUBTITLES_HEADER), | ||
g_localizeStrings.Get(STRING_TOAST_TEXT_ERROR), TOAST_DISPLAY_TIME, false); | ||
return false; | ||
} | ||
|
||
CGUIDialogSelect* dialog = | ||
CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogSelect>( | ||
WINDOW_DIALOG_SELECT); | ||
if (dialog == NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return false; | ||
|
||
CFileItemList options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would define vars where they are actually first used. |
||
|
||
int subtitleStreamCount = g_application.GetAppPlayer().GetSubtitleCount(); | ||
int currentSubtitle = g_application.GetAppPlayer().GetSubtitle(); | ||
if (!g_application.GetAppPlayer().GetSubtitleVisible()) | ||
currentSubtitle = -1; | ||
|
||
//Add the Disabled Element | ||
{ | ||
CFileItemPtr item(new CFileItem(g_localizeStrings.Get(1223).c_str())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
item->SetProperty("value", -1); | ||
if (currentSubtitle == -1) | ||
item->Select(true); | ||
options.Add(item); | ||
} | ||
|
||
// cycle through each subtitle and add it to our entry list | ||
for (int i = 0; i < subtitleStreamCount; ++i) | ||
{ | ||
SubtitleStreamInfo info; | ||
g_application.GetAppPlayer().GetSubtitleStreamInfo(i, info); | ||
|
||
std::string strItem; | ||
std::string strLanguage; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would define vars where they are actually first used. |
||
|
||
if (!g_LangCodeExpander.Lookup(info.language, strLanguage)) | ||
strLanguage = g_localizeStrings.Get(13205); // Unknown | ||
|
||
if (info.name.length() == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
strItem = strLanguage; | ||
else | ||
strItem = StringUtils::Format("%s - %s", strLanguage.c_str(), info.name.c_str()); | ||
|
||
CFileItemPtr item(new CFileItem(strItem.c_str())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
item->SetProperty("value", i); | ||
|
||
if (i == currentSubtitle) | ||
item->Select(true); | ||
|
||
options.Add(item); | ||
} | ||
|
||
if (options.Size() < 2) | ||
{ | ||
CGUIDialogKaiToast::QueueNotification( | ||
CGUIDialogKaiToast::Info, g_localizeStrings.Get(STRING_SUBTITLES_HEADER), | ||
g_localizeStrings.Get(STRING_TOAST_TEXT_ERROR), TOAST_DISPLAY_TIME, false); | ||
return true; | ||
} | ||
|
||
dialog->Reset(); | ||
dialog->SetHeading(g_localizeStrings.Get(STRING_SUBTITLES_HEADER).c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
dialog->SetItems(options); | ||
dialog->SetMultiSelection(false); | ||
dialog->Open(); | ||
|
||
if (!dialog->IsConfirmed()) | ||
return true; | ||
|
||
int selected = dialog->GetSelectedItem() - 1; | ||
if (selected == currentSubtitle) | ||
{ | ||
if (!g_application.GetAppPlayer().GetSubtitleVisible()) | ||
g_application.GetAppPlayer().SetSubtitleVisible(true); | ||
} | ||
else if (selected == -1) | ||
{ | ||
g_application.GetAppPlayer().SetSubtitleVisible(false); | ||
} | ||
else | ||
{ | ||
g_application.GetAppPlayer().SetSubtitle(selected); | ||
g_application.GetAppPlayer().SetSubtitleVisible(true); | ||
} | ||
|
||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong include order