summaryrefslogtreecommitdiffstats
path: root/xbmc/interfaces/builtins/PictureBuiltins.cpp
blob: 15cfe0a982bab40b4d19cf469a4e98a29c4971b9 (plain)
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
/*
 *  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 "PictureBuiltins.h"

#include "GUIUserMessages.h"
#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "utils/StringUtils.h"

/*! \brief Show a picture.
 *  \param params The parameters.
 *  \details params[0] = URL of picture.
 */
static int Show(const std::vector<std::string>& params)
{
  CGUIMessage msg(GUI_MSG_SHOW_PICTURE, 0, 0);
  msg.SetStringParam(params[0]);
  CGUIWindow *pWindow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_SLIDESHOW);
  if (pWindow)
    pWindow->OnMessage(msg);

  return 0;
}

/*! \brief Start a slideshow.
 *  \param params The parameters.
 *  \details params[0] = Path to run slideshow for.
 *           params[1,..] = "recursive" to run a recursive slideshow.
 *           params[1,...] = "random" to randomize slideshow.
 *           params[1,...] = "notrandom" to not randomize slideshow.
 *           params[1,...] = "pause" to start slideshow paused.
 *           params[1,...] = "beginslide=<number>" to start at a given slide.
 *
 *  Set the template parameter Recursive to true to run a recursive slideshow.
 */
  template<bool Recursive>
static int Slideshow(const std::vector<std::string>& params)
{
  std::string beginSlidePath;
  // leave RecursiveSlideShow command as-is
  unsigned int flags = 0;
  if (Recursive)
    flags |= 1;

  // SlideShow(dir[,recursive][,[not]random][,pause][,beginslide="/path/to/start/slide.jpg"])
  // the beginslide value need be escaped (for '"' or '\' in it, by backslash)
  // and then quoted, or not. See CUtil::SplitParams()
  else
  {
    for (unsigned int i = 1 ; i < params.size() ; i++)
    {
      if (StringUtils::EqualsNoCase(params[i], "recursive"))
        flags |= 1;
      else if (StringUtils::EqualsNoCase(params[i], "random")) // set fullscreen or windowed
        flags |= 2;
      else if (StringUtils::EqualsNoCase(params[i], "notrandom"))
        flags |= 4;
      else if (StringUtils::EqualsNoCase(params[i], "pause"))
        flags |= 8;
      else if (StringUtils::StartsWithNoCase(params[i], "beginslide="))
        beginSlidePath = params[i].substr(11);
    }
  }

  CGUIMessage msg(GUI_MSG_START_SLIDESHOW, 0, 0, flags);
  std::vector<std::string> strParams;
  strParams.push_back(params[0]);
  strParams.push_back(beginSlidePath);
  msg.SetStringParams(strParams);
  CGUIWindow *pWindow = CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_SLIDESHOW);
  if (pWindow)
    pWindow->OnMessage(msg);

  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_11 Picture built-in's
///
/// -----------------------------------------------------------------------------
///
/// \table_start
///   \table_h2_l{
///     Function,
///     Description }
///   \table_row2_l{
///     <b>`RecursiveSlideShow(dir)`</b>
///     ,
///     Run a slideshow from the specified directory\, including all subdirs.
///     @param[in] dir                   Path to run slideshow for.
///     @param[in] random                Add "random" to randomize slideshow (optional).
///     @param[in] notrandom             Add "notrandom" to not randomize slideshow (optional).
///     @param[in] pause                 Add "pause" to start slideshow paused (optional).
///     @param[in] beginslide            Add "beginslide=<number>" to start at a given slide (optional).
///   }
///   \table_row2_l{
///     <b>`ShowPicture(picture)`</b>
///     ,
///     Display a picture by file path.
///     @param[in] url                    URL of picture.
///   }
///   \table_row2_l{
///     <b>`SlideShow(dir [\,recursive\, [not]random])`</b>
///     ,
///     Starts a slideshow of pictures in the folder dir. Optional parameters are
///     <b>recursive</b>\, and **random** or **notrandom** slideshow\, adding images
///     from sub-folders. The **random** and **notrandom** parameters override
///     the Randomize setting found in the pictures media window.
///     @param[in] dir                   Path to run slideshow for.
///     @param[in] recursive             Add "recursive" to run a recursive slideshow (optional).
///     @param[in] random                Add "random" to randomize slideshow (optional).
///     @param[in] notrandom             Add "notrandom" to not randomize slideshow (optional).
///     @param[in] pause                 Add "pause" to start slideshow paused (optional).
///     @param[in] beginslide            Add "beginslide=<number>" to start at a given slide (optional).
///   }
/// \table_end
///

CBuiltins::CommandMap CPictureBuiltins::GetOperations() const
{
  return {
           {"recursiveslideshow", {"Run a slideshow from the specified directory, including all subdirs", 1, Slideshow<true>}},
           {"showpicture",        {"Display a picture by file path", 1, Show}},
           {"slideshow",          {"Run a slideshow from the specified directory", 1, Slideshow<false>}}
         };
}