diff options
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogFileBrowser.h')
| -rw-r--r-- | xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogFileBrowser.h | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogFileBrowser.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogFileBrowser.h new file mode 100644 index 0000000..e348125 --- /dev/null +++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/gui/DialogFileBrowser.h | |||
| @@ -0,0 +1,293 @@ | |||
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2005-2017 Team KODI | ||
| 4 | * http://kodi.tv | ||
| 5 | * | ||
| 6 | * This Program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2, or (at your option) | ||
| 9 | * any later version. | ||
| 10 | * | ||
| 11 | * This Program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with KODI; see the file COPYING. If not, see | ||
| 18 | * <http://www.gnu.org/licenses/>. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include "definitions.h" | ||
| 23 | #include "../AddonBase.h" | ||
| 24 | |||
| 25 | namespace kodi | ||
| 26 | { | ||
| 27 | namespace gui | ||
| 28 | { | ||
| 29 | |||
| 30 | //============================================================================ | ||
| 31 | /// | ||
| 32 | /// \defgroup cpp_kodi_gui_DialogFileBrowser Dialog File Browser | ||
| 33 | /// \ingroup cpp_kodi_gui | ||
| 34 | /// @brief \cpp_namespace{ kodi::gui::DialogFileBrowser } | ||
| 35 | /// **File browser dialog** | ||
| 36 | /// | ||
| 37 | /// The functions listed below of the class "DialogFileBrowser" offer | ||
| 38 | /// the possibility to select to a file by the user of the add-on. | ||
| 39 | /// | ||
| 40 | /// It allows all the options that are possible in Kodi itself and offers all | ||
| 41 | /// support file types. | ||
| 42 | /// | ||
| 43 | /// It has the header \ref DialogFileBrowser.h "#include <kodi/gui/DialogFileBrowser.h>" | ||
| 44 | /// be included to enjoy it. | ||
| 45 | /// | ||
| 46 | namespace DialogFileBrowser | ||
| 47 | { | ||
| 48 | //========================================================================== | ||
| 49 | /// | ||
| 50 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 51 | /// @brief Directory selection dialog | ||
| 52 | /// | ||
| 53 | /// @param[in] shares With Shares becomes the available start folders | ||
| 54 | /// be set. | ||
| 55 | /// @param[in] heading Dialog header name | ||
| 56 | /// @param[in,out] path As in the path to start and return value about | ||
| 57 | /// selected directory | ||
| 58 | /// @param[in] writeOnly If set only writeable folders are shown. | ||
| 59 | /// @return False if selection becomes canceled. | ||
| 60 | /// | ||
| 61 | /// **Example:** | ||
| 62 | /// ~~~~~~~~~~~~~{.cpp} | ||
| 63 | /// #include <kodi/gui/DialogFileBrowser.h> | ||
| 64 | /// | ||
| 65 | /// /* | ||
| 66 | /// * Example show directory selection dialog with on 'share' (first value) | ||
| 67 | /// * defined directory types. | ||
| 68 | /// * | ||
| 69 | /// * If this becomes leaved empty and 'directory' is empty goes it to the | ||
| 70 | /// * base path of the hard disk. | ||
| 71 | /// * | ||
| 72 | /// * Also can be with path written to 'directory' before the dialog forced | ||
| 73 | /// * to a start place. | ||
| 74 | /// */ | ||
| 75 | /// std::string directory; | ||
| 76 | /// bool ret = kodi::gui::DialogFileBrowser::ShowAndGetDirectory("local|network|removable", | ||
| 77 | /// "Test directory selection", | ||
| 78 | /// directory, | ||
| 79 | /// false); | ||
| 80 | /// fprintf(stderr, "Selected directory is : %s and was %s\n", directory.c_str(), ret ? "OK" : "Canceled"); | ||
| 81 | /// ~~~~~~~~~~~~~ | ||
| 82 | /// | ||
| 83 | inline bool ShowAndGetDirectory(const std::string& shares, const std::string& heading, std::string& path, bool writeOnly = false) | ||
| 84 | { | ||
| 85 | using namespace ::kodi::addon; | ||
| 86 | char* retString = nullptr; | ||
| 87 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_directory(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 88 | shares.c_str(), heading.c_str(), path.c_str(), &retString, writeOnly); | ||
| 89 | if (retString != nullptr) | ||
| 90 | { | ||
| 91 | if (std::strlen(retString)) | ||
| 92 | path = retString; | ||
| 93 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 94 | } | ||
| 95 | return ret; | ||
| 96 | } | ||
| 97 | //-------------------------------------------------------------------------- | ||
| 98 | |||
| 99 | //========================================================================== | ||
| 100 | /// | ||
| 101 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 102 | /// @brief File selection dialog | ||
| 103 | /// | ||
| 104 | /// @param[in] shares With Shares becomes the available start | ||
| 105 | /// folders be set. | ||
| 106 | /// @param[in] mask The mask to filter visible files, e.g. | ||
| 107 | /// ".m3u|.pls|.b4s|.wpl". | ||
| 108 | /// @param[in] heading Dialog header name | ||
| 109 | /// @param[in,out] path As in the path to start and Return value | ||
| 110 | /// about selected file | ||
| 111 | /// @param[in] useThumbs If set show thumbs if possible on dialog. | ||
| 112 | /// @param[in] useFileDirectories If set also packages (e.g. *.zip) are | ||
| 113 | /// handled as directories. | ||
| 114 | /// @return False if selection becomes canceled. | ||
| 115 | /// | ||
| 116 | inline bool ShowAndGetFile(const std::string& shares, const std::string& mask, const std::string& heading, | ||
| 117 | std::string& path, bool useThumbs = false, bool useFileDirectories = false) | ||
| 118 | { | ||
| 119 | using namespace ::kodi::addon; | ||
| 120 | char* retString = nullptr; | ||
| 121 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 122 | shares.c_str(), mask.c_str(), heading.c_str(), path.c_str(), &retString, | ||
| 123 | useThumbs, useFileDirectories); | ||
| 124 | if (retString != nullptr) | ||
| 125 | { | ||
| 126 | if (std::strlen(retString)) | ||
| 127 | path = retString; | ||
| 128 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 129 | } | ||
| 130 | return ret; | ||
| 131 | } | ||
| 132 | //-------------------------------------------------------------------------- | ||
| 133 | |||
| 134 | //========================================================================== | ||
| 135 | /// | ||
| 136 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 137 | /// @brief File selection from a directory | ||
| 138 | /// | ||
| 139 | /// @param[in] directory The directory name where the dialog | ||
| 140 | /// start, possible are normal names and | ||
| 141 | /// kodi's special names. | ||
| 142 | /// @param[in] mask The mask to filter visible files, e.g. | ||
| 143 | /// ".m3u|.pls|.b4s|.wpl". | ||
| 144 | /// @param[in] heading Dialog header name | ||
| 145 | /// @param[in,out] path As in the path to start and Return value | ||
| 146 | /// about selected file | ||
| 147 | /// @param[in] useThumbs If set show thumbs if possible on dialog. | ||
| 148 | /// @param[in] useFileDirectories If set also packages (e.g. *.zip) are | ||
| 149 | /// handled as directories. | ||
| 150 | /// @param[in] singleList | ||
| 151 | /// @return False if selection becomes canceled. | ||
| 152 | /// | ||
| 153 | inline bool ShowAndGetFileFromDir(const std::string& directory, const std::string& mask, const std::string& heading, std::string& path, | ||
| 154 | bool useThumbs = false, bool useFileDirectories = false, bool singleList = false) | ||
| 155 | { | ||
| 156 | using namespace ::kodi::addon; | ||
| 157 | char* retString = nullptr; | ||
| 158 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_from_dir(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 159 | directory.c_str(), mask.c_str(), heading.c_str(), | ||
| 160 | path.c_str(), &retString, useThumbs, | ||
| 161 | useFileDirectories, singleList); | ||
| 162 | if (retString != nullptr) | ||
| 163 | { | ||
| 164 | if (std::strlen(retString)) | ||
| 165 | path = retString; | ||
| 166 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 167 | } | ||
| 168 | return ret; | ||
| 169 | } | ||
| 170 | //-------------------------------------------------------------------------- | ||
| 171 | |||
| 172 | //========================================================================== | ||
| 173 | /// | ||
| 174 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 175 | /// @brief File selection dialog to get several in to a list | ||
| 176 | /// | ||
| 177 | /// @param[in] shares With Shares becomes the available start | ||
| 178 | /// folders be set. | ||
| 179 | /// @param[in] mask The mask to filter visible files, e.g. | ||
| 180 | /// ".m3u|.pls|.b4s|.wpl". | ||
| 181 | /// @param[in] heading Dialog header name | ||
| 182 | /// @param[out] fileList Return value about selected files | ||
| 183 | /// @param[in] useThumbs If set show thumbs if possible on dialog. | ||
| 184 | /// @param[in] useFileDirectories If set also packages (e.g. *.zip) are | ||
| 185 | /// handled as directories. | ||
| 186 | /// @return False if selection becomes canceled. | ||
| 187 | /// | ||
| 188 | inline bool ShowAndGetFileList(const std::string& shares, const std::string& mask, const std::string& heading, | ||
| 189 | std::vector<std::string>& fileList, bool useThumbs = false, bool useFileDirectories = false) | ||
| 190 | { | ||
| 191 | using namespace ::kodi::addon; | ||
| 192 | char** list = nullptr; | ||
| 193 | unsigned int listSize = 0; | ||
| 194 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_file_list(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 195 | shares.c_str(), mask.c_str(), heading.c_str(), &list, &listSize, | ||
| 196 | useThumbs, useFileDirectories); | ||
| 197 | if (ret) | ||
| 198 | { | ||
| 199 | for (unsigned int i = 0; i < listSize; ++i) | ||
| 200 | fileList.push_back(list[i]); | ||
| 201 | CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->clear_file_list(CAddonBase::m_interface->toKodi->kodiBase, &list, listSize); | ||
| 202 | } | ||
| 203 | return ret; | ||
| 204 | } | ||
| 205 | //-------------------------------------------------------------------------- | ||
| 206 | |||
| 207 | //========================================================================== | ||
| 208 | /// | ||
| 209 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 210 | /// @brief Source selection dialog | ||
| 211 | /// | ||
| 212 | /// @param[in,out] path As in the path to start and Return value | ||
| 213 | /// about selected source | ||
| 214 | /// @param[in] allowNetworkShares Allow also access to network | ||
| 215 | /// @param[in] additionalShare With additionalShare becomes the available | ||
| 216 | /// start folders be set (optional). | ||
| 217 | /// @param[in] type | ||
| 218 | /// @return False if selection becomes canceled. | ||
| 219 | /// | ||
| 220 | inline bool ShowAndGetSource(std::string& path, bool allowNetworkShares, const std::string& additionalShare = "", const std::string& type = "") | ||
| 221 | { | ||
| 222 | using namespace ::kodi::addon; | ||
| 223 | char* retString = nullptr; | ||
| 224 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_source(CAddonBase::m_interface->toKodi->kodiBase, path.c_str(), &retString, | ||
| 225 | allowNetworkShares, additionalShare.c_str(), type.c_str()); | ||
| 226 | if (retString != nullptr) | ||
| 227 | { | ||
| 228 | if (std::strlen(retString)) | ||
| 229 | path = retString; | ||
| 230 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 231 | } | ||
| 232 | return ret; | ||
| 233 | } | ||
| 234 | //-------------------------------------------------------------------------- | ||
| 235 | |||
| 236 | //========================================================================== | ||
| 237 | /// | ||
| 238 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 239 | /// @brief Image selection dialog | ||
| 240 | /// | ||
| 241 | /// @param[in] shares With Shares becomes the available start folders be | ||
| 242 | /// set. | ||
| 243 | /// @param[in] heading Dialog header name | ||
| 244 | /// @param[out] path Return value about selected image | ||
| 245 | /// @return False if selection becomes canceled. | ||
| 246 | /// | ||
| 247 | inline bool ShowAndGetImage(const std::string& shares, const std::string& heading, std::string& path) | ||
| 248 | { | ||
| 249 | using namespace ::kodi::addon; | ||
| 250 | char* retString = nullptr; | ||
| 251 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 252 | shares.c_str(), heading.c_str(), path.c_str(), &retString); | ||
| 253 | if (retString != nullptr) | ||
| 254 | { | ||
| 255 | if (std::strlen(retString)) | ||
| 256 | path = retString; | ||
| 257 | CAddonBase::m_interface->toKodi->free_string(CAddonBase::m_interface->toKodi->kodiBase, retString); | ||
| 258 | } | ||
| 259 | return ret; | ||
| 260 | } | ||
| 261 | //-------------------------------------------------------------------------- | ||
| 262 | |||
| 263 | //========================================================================== | ||
| 264 | /// | ||
| 265 | /// \ingroup cpp_kodi_gui_DialogFileBrowser | ||
| 266 | /// @brief Image selection dialog to get several in to a list | ||
| 267 | /// | ||
| 268 | /// @param[in] shares With Shares becomes the available start folders | ||
| 269 | /// be set. | ||
| 270 | /// @param[in] heading Dialog header name | ||
| 271 | /// @param[out] file_list Return value about selected images | ||
| 272 | /// @return False if selection becomes canceled. | ||
| 273 | /// | ||
| 274 | inline bool ShowAndGetImageList(const std::string& shares, const std::string& heading, std::vector<std::string>& file_list) | ||
| 275 | { | ||
| 276 | using namespace ::kodi::addon; | ||
| 277 | char** list = nullptr; | ||
| 278 | unsigned int listSize = 0; | ||
| 279 | bool ret = CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->show_and_get_image_list(CAddonBase::m_interface->toKodi->kodiBase, | ||
| 280 | shares.c_str(), heading.c_str(), &list, &listSize); | ||
| 281 | if (ret) | ||
| 282 | { | ||
| 283 | for (unsigned int i = 0; i < listSize; ++i) | ||
| 284 | file_list.push_back(list[i]); | ||
| 285 | CAddonBase::m_interface->toKodi->kodi_gui->dialogFileBrowser->clear_file_list(CAddonBase::m_interface->toKodi->kodiBase, &list, listSize); | ||
| 286 | } | ||
| 287 | return ret; | ||
| 288 | } | ||
| 289 | //-------------------------------------------------------------------------- | ||
| 290 | }; | ||
| 291 | |||
| 292 | } /* namespace gui */ | ||
| 293 | } /* namespace kodi */ | ||
