2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIDialogVisualisationPresetList.h"
22 #include "addons/Visualisation.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "guilib/GUIListContainer.h"
25 #include "GUIUserMessages.h"
27 #include "guilib/Key.h"
28 #include "guilib/LocalizeStrings.h"
29 #include "utils/StringUtils.h"
31 #define CONTROL_LIST 2
32 #define CONTROL_PRESETS_LABEL 3
33 #define CONTROL_NONE_AVAILABLE 4
35 using ADDON::CVisualisation;
37 CGUIDialogVisualisationPresetList::CGUIDialogVisualisationPresetList(void)
38 : CGUIDialog(WINDOW_DIALOG_VIS_PRESET_LIST, "VisualisationPresetList.xml")
41 m_vecPresets = new CFileItemList;
43 m_loadType = KEEP_IN_MEMORY;
46 CGUIDialogVisualisationPresetList::~CGUIDialogVisualisationPresetList(void)
51 bool CGUIDialogVisualisationPresetList::OnMessage(CGUIMessage &message)
53 switch (message.GetMessage())
57 if (message.GetSenderId() == CONTROL_LIST && (message.GetParam1() == ACTION_SELECT_ITEM ||
58 message.GetParam1() == ACTION_MOUSE_LEFT_CLICK))
60 //clicked - ask for the preset to be changed to the new one
61 CGUIListContainer *pList = (CGUIListContainer *)GetControl(CONTROL_LIST);
64 int iItem = pList->GetSelectedItem();
66 m_viz->OnAction(VIS_ACTION_LOAD_PRESET, (void *)&iItem);
72 case GUI_MSG_WINDOW_DEINIT:
73 case GUI_MSG_VISUALISATION_UNLOADING:
76 CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_LIST);
81 case GUI_MSG_VISUALISATION_LOADED:
83 SetVisualisation((CVisualisation*)message.GetPointer());
87 return CGUIDialog::OnMessage(message);
90 void CGUIDialogVisualisationPresetList::SetVisualisation(CVisualisation* vis)
100 void CGUIDialogVisualisationPresetList::FrameMove()
102 //FIXME we shouldn't have to check preset each frame
103 // a viz callback could push GUI_MSG_VISUALISATION_UPDATED
106 unsigned preset = m_viz->GetPreset();
107 if (preset != m_currentPreset && preset < (unsigned int)m_vecPresets->Size())
109 m_vecPresets->Get(m_currentPreset)->Select(false);
110 m_currentPreset = preset;
111 m_vecPresets->Get(m_currentPreset)->Select(true);
114 CGUIDialog::FrameMove();
117 void CGUIDialogVisualisationPresetList::OnInitWindow()
119 CGUIMessage msg(GUI_MSG_GET_VISUALISATION, 0, 0);
120 g_windowManager.SendMessage(msg);
121 SetVisualisation((CVisualisation*)msg.GetPointer());
122 CGUIDialog::OnInitWindow();
125 void CGUIDialogVisualisationPresetList::Update()
127 m_vecPresets->Clear();
128 CStdString strHeading;
131 strHeading = StringUtils::Format(g_localizeStrings.Get(13407).c_str(), m_viz->Name().c_str());
134 CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_LIST);
136 std::vector<CStdString> presets;
137 if (m_viz->GetPresetList(presets))
139 m_currentPreset = m_viz->GetPreset();
140 for (unsigned i = 0; i < presets.size(); i++)
142 CFileItemPtr pItem(new CFileItem(presets[i]));
143 if (i == m_currentPreset)
145 pItem->RemoveExtension();
146 pItem->SetLabel2(" ");
147 m_vecPresets->Add(pItem);
149 CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_LIST, 0, 0, m_vecPresets);
154 // update our dialog's label
155 SET_CONTROL_LABEL(CONTROL_PRESETS_LABEL, strHeading);
157 // if there is no presets, add a label saying so
158 if (m_vecPresets->Size() == 0)
160 SET_CONTROL_VISIBLE(CONTROL_NONE_AVAILABLE);
164 SET_CONTROL_HIDDEN(CONTROL_NONE_AVAILABLE);
165 CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), CONTROL_LIST, m_currentPreset);