1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* 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 "GUIContainerBuiltins.h"
#include "GUIUserMessages.h"
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "utils/StringUtils.h"
/*! \brief Change sort method.
* \param params (ignored)
*
* Set the Dir template parameter to 1 to switch to next sort method
* or -1 to switch to previous sort method.
*/
template<int Dir>
static int ChangeSortMethod(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_CHANGE_SORT_METHOD, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, 0, Dir);
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Change view mode.
* \param params (ignored)
*
* Set the Dir template parameter to 1 to switch to next view mode
* or -1 to switch to previous view mode.
*/
template<int Dir>
static int ChangeViewMode(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_CHANGE_VIEW_MODE, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, 0, Dir);
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Refresh a media window.
* \param params The parameters.
* \details params[0] = The URL to refresh window at.
*/
static int Refresh(const std::vector<std::string>& params)
{ // NOTE: These messages require a media window, thus they're sent to the current activewindow.
// This shouldn't stop a dialog intercepting it though.
CGUIMessage message(GUI_MSG_NOTIFY_ALL, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, GUI_MSG_UPDATE, 1); // 1 to reset the history
message.SetStringParam(!params.empty() ? params[0] : "");
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Set sort method.
* \param params The parameters.
* \details params[0] = ID of sort method.
*/
static int SetSortMethod(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_CHANGE_SORT_METHOD, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, atoi(params[0].c_str()));
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Set view mode.
* \param params The parameters.
* \details params[0] = ID of view mode.
*/
static int SetViewMode(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_CHANGE_VIEW_MODE, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, atoi(params[0].c_str()));
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Toggle sort direction.
* \param params (ignored)
*/
static int ToggleSortDirection(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_CHANGE_SORT_DIRECTION, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, 0);
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
/*! \brief Update a listing in a media window.
* \param params The parameters.
* \details params[0] = The URL to update listing at.
* params[1] = "replace" to reset history (optional).
*/
static int Update(const std::vector<std::string>& params)
{
CGUIMessage message(GUI_MSG_NOTIFY_ALL, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow(), 0, GUI_MSG_UPDATE, 0);
message.SetStringParam(params[0]);
if (params.size() > 1 && StringUtils::EqualsNoCase(params[1], "replace"))
message.SetParam2(1); // reset the history
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(message);
return 0;
}
// Note: For new Texts with comma add a "\" before!!! Is used for table text.
//
/// \page page_List_of_built_in_functions
/// \section built_in_functions_6 GUI container built-in's
///
/// -----------------------------------------------------------------------------
///
/// \table_start
/// \table_h2_l{
/// Function,
/// Description }
/// \table_row2_l{
/// <b>`Container.NextSortMethod`</b>
/// ,
/// Change to the next sort method.
/// }
/// \table_row2_l{
/// <b>`Container.NextViewMode`</b>
/// ,
/// Select the next view mode.
/// }
/// \table_row2_l{
/// <b>`Container.PreviousSortMethod`</b>
/// ,
/// Change to the previous sort method.
/// }
/// \table_row2_l{
/// <b>`Container.PreviousViewMode`</b>
/// ,
/// Select the previous view mode.
/// }
/// \table_row2_l{
/// <b>`Container.Refresh(url)`</b>
/// ,
/// Refresh current listing
/// @param[in] url The URL to refresh window at.
/// }
/// \table_row2_l{
/// <b>`Container.SetSortMethod(id)`</b>
/// ,
/// Change to the specified sort method. (For list of ID's \ref SortBy "see List" of sort methods below)
/// @param[in] id ID of sort method.
/// }
/// \table_row2_l{
/// <b>`Container.SetViewMode(id)`</b>
/// ,
/// Set the current view mode (list\, icons etc.) to the given container id.
/// @param[in] id ID of view mode.
/// }
/// \table_row2_l{
/// <b>`Container.SortDirection`</b>
/// ,
/// Toggle the sort direction
/// }
/// \table_row2_l{
/// <b>`Container.Update(url\,[replace])`</b>
/// ,
/// Update current listing. Send `Container.Update(path\,replace)` to reset the path history.
/// @param[in] url The URL to update listing at.
/// @param[in] replace "replace" to reset history (optional).
/// }
/// \table_end
///
CBuiltins::CommandMap CGUIContainerBuiltins::GetOperations() const
{
return {
{"container.nextsortmethod", {"Change to the next sort method", 0, ChangeSortMethod<1>}},
{"container.nextviewmode", {"Move to the next view type (and refresh the listing)", 0, ChangeViewMode<1>}},
{"container.previoussortmethod", {"Change to the previous sort method", 0, ChangeSortMethod<-1>}},
{"container.previousviewmode", {"Move to the previous view type (and refresh the listing)", 0, ChangeViewMode<-1>}},
{"container.refresh", {"Refresh current listing", 0, Refresh}},
{"container.setsortdirection", {"Toggle the sort direction", 0, ToggleSortDirection}},
{"container.setsortmethod", {"Change to the specified sort method", 1, SetSortMethod}},
{"container.setviewmode", {"Move to the view with the given id", 1, SetViewMode}},
{"container.update", {"Update current listing. Send Container.Update(path,replace) to reset the path history", 1, Update}}
};
}
|