Skip to content

Commit

Permalink
Merge pull request xbmc#8395 from Razzeee/music-ask-to-scan
Browse files Browse the repository at this point in the history
[music] When adding a new music directory, ask the user if he wants t…
  • Loading branch information
MartijnKaijser committed Nov 20, 2015
2 parents cc12679 + ae350a8 commit 275fc3f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 55 deletions.
10 changes: 8 additions & 2 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -11852,7 +11852,10 @@ msgctxt "#20443"
msgid "Do you want to refresh information for all items within this path?"
msgstr ""

#empty string with id 20444
#: xbmc/music/windows/GUIWindowMusicBase.cpp
msgctxt "#20444"
msgid "Add to library"
msgstr ""

#: xbmc/music/dialogs/GUIDialogMusicInfo.cpp
msgctxt "#20445"
Expand All @@ -11863,7 +11866,10 @@ msgctxt "#20446"
msgid "Locally stored information found. Ignore and refresh from Internet?"
msgstr ""

#empty string with id 20447
#: xbmc/music/windows/GUIWindowMusicBase.cpp
msgctxt "#20447"
msgid "Do you want to add the media from this source to your library?"
msgstr ""

#: xbmc/video/VideoInfoScanner.cpp
msgctxt "#20448"
Expand Down
107 changes: 55 additions & 52 deletions xbmc/dialogs/GUIDialogMediaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "guilib/GUIKeyboardFactory.h"
#include "GUIDialogFileBrowser.h"
#include "video/windows/GUIWindowVideoBase.h"
#include "music/windows/GUIWindowMusicBase.h"
#include "guilib/GUIWindowManager.h"
#include "input/Key.h"
#include "Util.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ CGUIDialogMediaSource::CGUIDialogMediaSource(void)
, m_confirmed(false)
, m_bNameChanged(false)
{
m_paths = new CFileItemList;
m_paths = new CFileItemList;
m_loadType = KEEP_IN_MEMORY;
}

Expand All @@ -78,43 +79,43 @@ bool CGUIDialogMediaSource::OnBack(int actionID)

bool CGUIDialogMediaSource::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
switch (message.GetMessage())
{
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
int iAction = message.GetParam1();
if (iControl == CONTROL_PATH && (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK))
OnPath(GetSelectedItem());
else if (iControl == CONTROL_PATH_BROWSE)
OnPathBrowse(GetSelectedItem());
else if (iControl == CONTROL_PATH_ADD)
OnPathAdd();
else if (iControl == CONTROL_PATH_REMOVE)
OnPathRemove(GetSelectedItem());
else if (iControl == CONTROL_NAME)
{
int iControl = message.GetSenderId();
int iAction = message.GetParam1();
if (iControl == CONTROL_PATH && (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK))
OnPath(GetSelectedItem());
else if (iControl == CONTROL_PATH_BROWSE)
OnPathBrowse(GetSelectedItem());
else if (iControl == CONTROL_PATH_ADD)
OnPathAdd();
else if (iControl == CONTROL_PATH_REMOVE)
OnPathRemove(GetSelectedItem());
else if (iControl == CONTROL_NAME)
{
OnEditChanged(iControl, m_name);
UpdateButtons();
}
else if (iControl == CONTROL_OK)
OnOK();
else if (iControl == CONTROL_CANCEL)
OnCancel();
else
break;
return true;
}
break;
case GUI_MSG_WINDOW_INIT:
{
OnEditChanged(iControl, m_name);
UpdateButtons();
}
break;
else if (iControl == CONTROL_OK)
OnOK();
else if (iControl == CONTROL_CANCEL)
OnCancel();
else
break;
return true;
}
break;
case GUI_MSG_WINDOW_INIT:
{
UpdateButtons();
}
break;
case GUI_MSG_SETFOCUS:
if (message.GetControlId() == CONTROL_PATH_BROWSE ||
message.GetControlId() == CONTROL_PATH_ADD ||
message.GetControlId() == CONTROL_PATH_REMOVE)
message.GetControlId() == CONTROL_PATH_ADD ||
message.GetControlId() == CONTROL_PATH_REMOVE)
{
HighlightItem(GetSelectedItem());
}
Expand All @@ -139,13 +140,13 @@ bool CGUIDialogMediaSource::ShowAndAddMediaSource(const std::string &type)
if (confirmed)
{ // yay, add this share
CMediaSource share;
unsigned int i,j=2;
bool bConfirmed=false;
unsigned int i, j = 2;
bool bConfirmed = false;
VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(type);
std::string strName = dialog->m_name;
while (!bConfirmed)
{
for (i=0;i<pShares->size();++i)
for (i = 0;i<pShares->size();++i)
{
if (StringUtils::EqualsNoCase((*pShares)[i].strName, strName))
break;
Expand All @@ -170,10 +171,10 @@ bool CGUIDialogMediaSource::ShowAndEditMediaSource(const std::string &type, cons
VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(type);
if (pShares)
{
for (unsigned int i=0;i<pShares->size();++i)
for (unsigned int i = 0;i<pShares->size();++i)
{
if (StringUtils::EqualsNoCase((*pShares)[i].strName, share))
return ShowAndEditMediaSource(type,(*pShares)[i]);
return ShowAndEditMediaSource(type, (*pShares)[i]);
}
}
return false;
Expand All @@ -191,13 +192,13 @@ bool CGUIDialogMediaSource::ShowAndEditMediaSource(const std::string &type, cons
bool confirmed(dialog->IsConfirmed());
if (confirmed)
{ // yay, add this share
unsigned int i,j=2;
bool bConfirmed=false;
unsigned int i, j = 2;
bool bConfirmed = false;
VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(type);
std::string strName = dialog->m_name;
while (!bConfirmed)
{
for (i=0;i<pShares->size();++i)
for (i = 0;i<pShares->size();++i)
{
if (StringUtils::EqualsNoCase((*pShares)[i].strName, strName))
break;
Expand Down Expand Up @@ -226,7 +227,7 @@ void CGUIDialogMediaSource::OnPathBrowse(int item)
VECSOURCES extraShares;

if (m_name != CUtil::GetTitleFromPath(m_paths->Get(item)->GetPath()))
m_bNameChanged=true;
m_bNameChanged = true;

std::string strStreams = g_localizeStrings.Get(33039); //"% Streams"
std::string strDevices = g_localizeStrings.Get(33040); //"% Devices"
Expand Down Expand Up @@ -262,7 +263,7 @@ void CGUIDialogMediaSource::OnPathBrowse(int item)
share1.strName = g_localizeStrings.Get(21883);
extraShares.push_back(share1);
}
}
}
else if (m_type == "video")
{
CMediaSource share1;
Expand Down Expand Up @@ -308,7 +309,7 @@ void CGUIDialogMediaSource::OnPathBrowse(int item)
#if defined(TARGET_ANDROID)
// add the default android music directory
std::string path;
if (CXBMCApp::GetExternalStorage(path, "pictures") && !path.empty() && CFile::Exists(path))
if (CXBMCApp::GetExternalStorage(path, "pictures") && !path.empty() && CFile::Exists(path))
{
share1.strPath = path;
share1.strName = g_localizeStrings.Get(20242);
Expand All @@ -317,7 +318,7 @@ void CGUIDialogMediaSource::OnPathBrowse(int item)
}

path.clear();
if (CXBMCApp::GetExternalStorage(path, "photos") && !path.empty() && CFile::Exists(path))
if (CXBMCApp::GetExternalStorage(path, "photos") && !path.empty() && CFile::Exists(path))
{
share1.strPath = path;
share1.strName = g_localizeStrings.Get(20243);
Expand All @@ -338,7 +339,7 @@ void CGUIDialogMediaSource::OnPathBrowse(int item)
{
// nothing to add
}
if (CGUIDialogFileBrowser::ShowAndGetSource(path, allowNetworkShares, extraShares.size()==0?NULL:&extraShares))
if (CGUIDialogFileBrowser::ShowAndGetSource(path, allowNetworkShares, extraShares.size() == 0 ? NULL : &extraShares))
{
if (item < m_paths->Size()) // if the skin does funky things, m_paths may have been cleared
m_paths->Get(item)->SetPath(path);
Expand All @@ -358,10 +359,10 @@ void CGUIDialogMediaSource::OnPath(int item)
if (item < 0 || item > m_paths->Size()) return;

if (m_name != CUtil::GetTitleFromPath(m_paths->Get(item)->GetPath()))
m_bNameChanged=true;
m_bNameChanged = true;

std::string path(m_paths->Get(item)->GetPath());
CGUIKeyboardFactory::ShowAndGetInput(path, CVariant{g_localizeStrings.Get(1021)}, false);
CGUIKeyboardFactory::ShowAndGetInput(path, CVariant{ g_localizeStrings.Get(1021) }, false);
m_paths->Get(item)->SetPath(path);

if (!m_bNameChanged || m_name.empty())
Expand All @@ -385,15 +386,17 @@ void CGUIDialogMediaSource::OnOK()
VECSOURCES *shares = CMediaSourceSettings::GetInstance().GetSources(m_type);
if (shares)
shares->push_back(share);
if (StringUtils::StartsWithNoCase(share.strPath, "plugin://") || CDirectory::GetDirectory(share.strPath, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_ALLOW_PROMPT) || CGUIDialogYesNo::ShowAndGetInput(CVariant{1001}, CVariant{1025}))
if (StringUtils::StartsWithNoCase(share.strPath, "plugin://") || CDirectory::GetDirectory(share.strPath, items, "", DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_ALLOW_PROMPT) || CGUIDialogYesNo::ShowAndGetInput(CVariant{ 1001 }, CVariant{ 1025 }))
{
m_confirmed = true;
Close();
if (m_type == "video" && !URIUtils::IsLiveTV(share.strPath) &&
!StringUtils::StartsWithNoCase(share.strPath, "rss://") &&
!StringUtils::StartsWithNoCase(share.strPath, "upnp://"))
if (!StringUtils::StartsWithNoCase(share.strPath, "rss://") &&
!StringUtils::StartsWithNoCase(share.strPath, "upnp://"))
{
CGUIWindowVideoBase::OnAssignContent(share.strPath);
if (m_type == "video" && !URIUtils::IsLiveTV(share.strPath))
CGUIWindowVideoBase::OnAssignContent(share.strPath);
else if (m_type == "music")
CGUIWindowMusicBase::OnAssignContent(share.strPath);
}
}

Expand Down Expand Up @@ -428,7 +431,7 @@ void CGUIDialogMediaSource::UpdateButtons()
std::string path;
CURL url(item->GetPath());
path = url.GetWithoutUserDetails();
if (path.empty()) path = "<"+g_localizeStrings.Get(231)+">"; // <None>
if (path.empty()) path = "<" + g_localizeStrings.Get(231) + ">"; // <None>
item->SetLabel(path);
}
CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_PATH, 0, 0, m_paths);
Expand Down
10 changes: 10 additions & 0 deletions xbmc/music/windows/GUIWindowMusicBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,3 +1459,13 @@ void CGUIWindowMusicBase::OnPrepareFileItems(CFileItemList &items)
if (!items.IsMusicDb())
RetrieveMusicInfo();
}

void CGUIWindowMusicBase::OnAssignContent(const std::string &path)
{
// Add content selection logic here, if music is ready for that some day

// This won't ask you to clean/delete your content, when you change the scraper to none (if music gets this), might ne nice in the future
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{ 20444 }, CVariant{ 20447 }))
g_application.StartMusicScan(path, true);
}

5 changes: 5 additions & 0 deletions xbmc/music/windows/GUIWindowMusicBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class CGUIWindowMusicBase : public CGUIMediaWindow, public IBackgroundLoaderObse
void OnItemInfo(CFileItem *pItem, bool bShowInfo = false);

void DoScan(const std::string &strPath);

/*! \brief Prompt the user if he wants to start a scan for this folder
\param path the path to assign content for
*/
static void OnAssignContent(const std::string &path);
protected:
virtual void OnInitWindow();
/*!
Expand Down
2 changes: 1 addition & 1 deletion xbmc/music/windows/GUIWindowMusicNav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ bool CGUIWindowMusicNav::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
OnItemInfoAll(itemNumber,true,true);
}

}

return true;
}

Expand Down

0 comments on commit 275fc3f

Please sign in to comment.