ewk_file_chooser.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright (C) 2012 Samsung Electronics
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "config.h"
  17. #include "ewk_file_chooser.h"
  18. #include "FileChooser.h"
  19. #include "ewk_file_chooser_private.h"
  20. #include <wtf/text/CString.h>
  21. struct _Ewk_File_Chooser {
  22. RefPtr<WebCore::FileChooser> fileChooser;
  23. };
  24. Eina_Bool ewk_file_chooser_allows_multiple_files_get(const Ewk_File_Chooser* chooser)
  25. {
  26. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, false);
  27. return chooser->fileChooser->settings().allowsMultipleFiles;
  28. }
  29. Eina_Bool ewk_file_chooser_allows_directory_upload_get(const Ewk_File_Chooser* chooser)
  30. {
  31. #if ENABLE(DIRECTORY_UPLOAD)
  32. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, false);
  33. return chooser->fileChooser->settings().allowsDirectoryUpload;
  34. #else
  35. UNUSED_PARAM(chooser);
  36. return false;
  37. #endif
  38. }
  39. Eina_List* ewk_file_chooser_accept_mimetypes_get(const Ewk_File_Chooser* chooser)
  40. {
  41. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, 0);
  42. Eina_List* mimetypes = 0;
  43. size_t count = chooser->fileChooser->settings().acceptMIMETypes.size();
  44. for (size_t i = 0; i < count; ++i)
  45. mimetypes = eina_list_append(mimetypes, eina_stringshare_add(chooser->fileChooser->settings().acceptMIMETypes[i].utf8().data()));
  46. return mimetypes;
  47. }
  48. Eina_List* ewk_file_chooser_accept_file_extentions_get(const Ewk_File_Chooser* chooser)
  49. {
  50. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, 0);
  51. Eina_List* fileExtentions = 0;
  52. size_t count = chooser->fileChooser->settings().acceptFileExtensions.size();
  53. for (size_t i = 0; i < count; ++i)
  54. fileExtentions = eina_list_append(fileExtentions, eina_stringshare_add(chooser->fileChooser->settings().acceptFileExtensions[i].utf8().data()));
  55. return fileExtentions;
  56. }
  57. Eina_List* ewk_file_chooser_selected_files_get(const Ewk_File_Chooser* chooser)
  58. {
  59. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, 0);
  60. Eina_List* files = 0;
  61. size_t count = chooser->fileChooser->settings().selectedFiles.size();
  62. for (size_t i = 0; i < count; ++i)
  63. files = eina_list_append(files, eina_stringshare_add(chooser->fileChooser->settings().selectedFiles[i].utf8().data()));
  64. return files;
  65. }
  66. Ewk_File_Chooser_Capture_Type ewk_file_chooser_capture_get(const Ewk_File_Chooser* chooser)
  67. {
  68. #if ENABLE(MEDIA_CAPTURE)
  69. EINA_SAFETY_ON_NULL_RETURN_VAL(chooser, EWK_FILE_CHOOSER_CAPTURE_TYPE_INVALID);
  70. String capture = chooser->fileChooser->settings().capture;
  71. if (capture == "camera")
  72. return EWK_FILE_CHOOSER_CAPTURE_TYPE_CAMERA;
  73. if (capture == "camcorder")
  74. return EWK_FILE_CHOOSER_CAPTURE_TYPE_CAMCORDER;
  75. if (capture == "microphone")
  76. return EWK_FILE_CHOOSER_CAPTURE_TYPE_MICROPHONE;
  77. return EWK_FILE_CHOOSER_CAPTURE_TYPE_FILESYSTEM;
  78. #else
  79. UNUSED_PARAM(chooser);
  80. return EWK_FILE_CHOOSER_CAPTURE_TYPE_INVALID;
  81. #endif
  82. }
  83. Ewk_File_Chooser* ewk_file_chooser_new(WebCore::FileChooser* fileChooser)
  84. {
  85. Ewk_File_Chooser* ewkFileChooser = new Ewk_File_Chooser;
  86. ewkFileChooser->fileChooser = fileChooser;
  87. return ewkFileChooser;
  88. }
  89. void ewk_file_chooser_free(Ewk_File_Chooser* chooser)
  90. {
  91. chooser->fileChooser = 0;
  92. delete chooser;
  93. }