Permalink
Browse files

Merge pull request #1079 from Montellese/xsp_ext_ors

[GSoC] smartplaylist: support multiple OR'ed conditions in a single rule
  • Loading branch information...
Montellese committed Jul 1, 2012
2 parents 1da97bf + 171e25a commit 12f9cb7dcb1bb0fea61d1898cf32d43101d85179
@@ -56,6 +56,7 @@ bool CGUIDialogSelect::OnMessage(CGUIMessage& message)
{
CGUIDialog::OnMessage(message);
m_viewControl.Reset();
+
m_bButtonEnabled = false;
m_useDetails = false;
m_multiSelection = false;
@@ -83,6 +84,7 @@ bool CGUIDialogSelect::OnMessage(CGUIMessage& message)
case GUI_MSG_WINDOW_INIT:
{
m_bButtonPressed = false;
+ m_bConfirmed = false;
CGUIDialog::OnMessage(message);
return true;
}
@@ -108,6 +110,7 @@ bool CGUIDialogSelect::OnMessage(CGUIMessage& message)
for (int i = 0 ; i < m_vecList->Size() ; i++)
m_vecList->Get(i)->Select(false);
item->Select(true);
+ m_bConfirmed = true;
Close();
}
}
@@ -117,6 +120,8 @@ bool CGUIDialogSelect::OnMessage(CGUIMessage& message)
{
m_iSelected = -1;
m_bButtonPressed = true;
+ if (m_multiSelection)
+ m_bConfirmed = true;
Close();
}
}
@@ -138,6 +143,8 @@ bool CGUIDialogSelect::OnMessage(CGUIMessage& message)
bool CGUIDialogSelect::OnBack(int actionID)
{
m_iSelected = -1;
+ m_selectedItems->Clear();
+ m_bConfirmed = false;
return CGUIDialog::OnBack(actionID);
}
@@ -218,15 +225,63 @@ void CGUIDialogSelect::Sort(bool bSortOrder /*=true*/)
void CGUIDialogSelect::SetSelected(int iSelected)
{
- if (iSelected < 0 || iSelected >= (int)m_vecList->Size()) return;
- m_iSelected = iSelected;
+ if (iSelected < 0 || iSelected >= (int)m_vecList->Size() ||
+ m_vecList->Get(iSelected).get() == NULL)
+ return;
+
+ // only set m_iSelected if there is no multi-select
+ // or if it doesn't have a valid value yet
+ // or if the current value is bigger than the new one
+ // so that we always focus the item nearest to the beginning of the list
+ if (!m_multiSelection || m_iSelected < 0 || m_iSelected > iSelected)
+ m_iSelected = iSelected;
+ m_vecList->Get(iSelected)->Select(true);
+ m_selectedItems->Add(m_vecList->Get(iSelected));
+}
+
+void CGUIDialogSelect::SetSelected(const CStdString &strSelectedLabel)
+{
+ if (strSelectedLabel.empty())
+ return;
+
+ for (int index = 0; index < m_vecList->Size(); index++)
+ {
+ if (strSelectedLabel.Equals(m_vecList->Get(index)->GetLabel()))
+ {
+ SetSelected(index);
+ return;
+ }
+ }
+}
+
+void CGUIDialogSelect::SetSelected(std::vector<int> selectedIndexes)
+{
+ if (selectedIndexes.empty())
+ return;
+
+ for (std::vector<int>::const_iterator it = selectedIndexes.begin(); it != selectedIndexes.end(); it++)
+ SetSelected(*it);
+}
+
+void CGUIDialogSelect::SetSelected(const std::vector<CStdString> &selectedLabels)
+{
+ if (selectedLabels.empty())
+ return;
+
+ for (std::vector<CStdString>::const_iterator it = selectedLabels.begin(); it != selectedLabels.end(); it++)
+ SetSelected(*it);
}
void CGUIDialogSelect::SetUseDetails(bool useDetails)
{
m_useDetails = useDetails;
}
+void CGUIDialogSelect::SetMultiSelection(bool multiSelection)
+{
+ m_multiSelection = multiSelection;
+}
+
CGUIControl *CGUIDialogSelect::GetFirstFocusableControl(int id)
{
if (m_viewControl.HasControl(id))
@@ -263,6 +318,9 @@ void CGUIDialogSelect::OnInitWindow()
CStdString items;
items.Format("%i %s", m_vecList->Size(), g_localizeStrings.Get(127).c_str());
SET_CONTROL_LABEL(CONTROL_NUMBEROFFILES, items);
+
+ if (m_multiSelection)
+ EnableButton(true, 186);
if (m_bButtonEnabled)
{
@@ -50,8 +50,11 @@ class CGUIDialogSelect :
bool IsButtonPressed();
void Sort(bool bSortOrder = true);
void SetSelected(int iSelected);
+ void SetSelected(const CStdString &strSelectedLabel);
+ void SetSelected(std::vector<int> selectedIndexes);
+ void SetSelected(const std::vector<CStdString> &selectedLabels);
void SetUseDetails(bool useDetails);
- void SetMultiSelection(bool multiSelection) { m_multiSelection = multiSelection; };
+ void SetMultiSelection(bool multiSelection);
protected:
virtual CGUIControl *GetFirstFocusableControl(int id);
virtual void OnWindowLoaded();
@@ -274,7 +274,7 @@ void CGUIDialogSmartPlaylistEditor::UpdateButtons()
if (m_playlist.m_playlistRules[i].m_field == FieldNone)
item->SetLabel(g_localizeStrings.Get(21423));
else
- item->SetLabel(m_playlist.m_playlistRules[i].GetLocalizedRule());
+ item->SetLabel(m_playlist.m_playlistRules[i].GetLocalizedRule(m_playlist.GetType()));
m_ruleLabels->Add(item);
}
CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_RULE_LIST, 0, 0, m_ruleLabels);
@@ -68,8 +68,15 @@ bool CGUIDialogSmartPlaylistRule::OnMessage(CGUIMessage& message)
OnOK();
else if (iControl == CONTROL_CANCEL)
OnCancel();
- else if (iControl == CONTROL_VALUE)
- OnEditChanged(iControl, m_rule.m_parameter);
+ else if (iControl == CONTROL_VALUE && CSmartPlaylistRule::GetFieldType(m_rule.m_field) != CSmartPlaylistRule::BROWSEABLE_FIELD)
+ {
+ CStdString parameter;
+ OnEditChanged(iControl, parameter);
+ m_rule.m_parameter.clear();
+
+ if (!parameter.empty())
+ m_rule.m_parameter.push_back(parameter);
+ }
else if (iControl == CONTROL_OPERATOR)
OnOperator();
else if (iControl == CONTROL_FIELD)
@@ -218,7 +225,7 @@ void CGUIDialogSmartPlaylistRule::OnBrowse()
}
g_mediaManager.GetLocalDrives(sources);
- CGUIDialogFileBrowser::ShowAndGetDirectory(sources,g_localizeStrings.Get(657),m_rule.m_parameter,false);
+ CGUIDialogFileBrowser::ShowAndGetDirectory(sources,g_localizeStrings.Get(657),m_rule.GetLocalizedParameter(m_type),false);
UpdateButtons();
return;
}
@@ -241,10 +248,19 @@ void CGUIDialogSmartPlaylistRule::OnBrowse()
CStdString strHeading;
strHeading.Format(g_localizeStrings.Get(13401),g_localizeStrings.Get(iLabel));
pDialog->SetHeading(strHeading);
+ pDialog->SetMultiSelection(true);
+
+ if (!m_rule.m_parameter.empty())
+ pDialog->SetSelected(m_rule.m_parameter);
+
pDialog->DoModal();
- if (pDialog->GetSelectedLabel() > -1)
+ if (pDialog->IsConfirmed())
{
- m_rule.m_parameter = pDialog->GetSelectedLabelText();
+ const CFileItemList &items = pDialog->GetSelectedItems();
+ m_rule.m_parameter.clear();
+ for (int index = 0; index < items.Size(); index++)
+ m_rule.m_parameter.push_back(items[index]->GetLabel());
+
UpdateButtons();
}
pDialog->Reset();
@@ -344,13 +360,15 @@ void CGUIDialogSmartPlaylistRule::UpdateButtons()
m_rule.m_operator = (CSmartPlaylistRule::SEARCH_OPERATOR)selected.GetParam1();
// update the parameter edit control appropriately
- SET_CONTROL_LABEL2(CONTROL_VALUE, m_rule.m_parameter);
+ SET_CONTROL_LABEL2(CONTROL_VALUE, m_rule.GetLocalizedParameter(m_type));
CGUIEditControl::INPUT_TYPE type = CGUIEditControl::INPUT_TYPE_TEXT;
CSmartPlaylistRule::FIELD_TYPE fieldType = CSmartPlaylistRule::GetFieldType(m_rule.m_field);
switch (fieldType)
{
- case CSmartPlaylistRule::TEXT_FIELD:
case CSmartPlaylistRule::BROWSEABLE_FIELD:
+ type = CGUIEditControl::INPUT_TYPE_READONLY;
+ break;
+ case CSmartPlaylistRule::TEXT_FIELD:
case CSmartPlaylistRule::PLAYLIST_FIELD:
case CSmartPlaylistRule::TEXTIN_FIELD:
case CSmartPlaylistRule::NUMERIC_FIELD:
Oops, something went wrong.

0 comments on commit 12f9cb7

Please sign in to comment.