/indra/newview/llfilepicker.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 199 lines · 114 code · 33 blank · 52 comment · 0 complexity · 989af96755490e8994dca770389c161d MD5 · raw file

  1. /**
  2. * @file llfilepicker.h
  3. * @brief OS-specific file picker
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // OS specific file selection dialog. This is implemented as a
  27. // singleton class, so call the instance() method to get the working
  28. // instance. When you call getMultipleOpenFile(), it locks the picker
  29. // until you iterate to the end of the list of selected files with
  30. // getNextFile() or call reset().
  31. #ifndef LL_LLFILEPICKER_H
  32. #define LL_LLFILEPICKER_H
  33. #include "stdtypes.h"
  34. #if LL_DARWIN
  35. #include <Carbon/Carbon.h>
  36. // AssertMacros.h does bad things.
  37. #undef verify
  38. #undef check
  39. #undef require
  40. #include <vector>
  41. #include "llstring.h"
  42. #endif
  43. // Need commdlg.h for OPENFILENAMEA
  44. #ifdef LL_WINDOWS
  45. #include <commdlg.h>
  46. #endif
  47. extern "C" {
  48. // mostly for Linux, possible on others
  49. #if LL_GTK
  50. # include "gtk/gtk.h"
  51. #endif // LL_GTK
  52. }
  53. class LLFilePicker
  54. {
  55. #ifdef LL_GTK
  56. friend class LLDirPicker;
  57. friend void chooser_responder(GtkWidget *, gint, gpointer);
  58. #endif // LL_GTK
  59. public:
  60. // calling this before main() is undefined
  61. static LLFilePicker& instance( void ) { return sInstance; }
  62. enum ELoadFilter
  63. {
  64. FFLOAD_ALL = 1,
  65. FFLOAD_WAV = 2,
  66. FFLOAD_IMAGE = 3,
  67. FFLOAD_ANIM = 4,
  68. #ifdef _CORY_TESTING
  69. FFLOAD_GEOMETRY = 5,
  70. #endif
  71. FFLOAD_XML = 6,
  72. FFLOAD_SLOBJECT = 7,
  73. FFLOAD_RAW = 8,
  74. FFLOAD_MODEL = 9,
  75. FFLOAD_COLLADA = 10,
  76. FFLOAD_SCRIPT = 11,
  77. };
  78. enum ESaveFilter
  79. {
  80. FFSAVE_ALL = 1,
  81. FFSAVE_WAV = 3,
  82. FFSAVE_TGA = 4,
  83. FFSAVE_BMP = 5,
  84. FFSAVE_AVI = 6,
  85. FFSAVE_ANIM = 7,
  86. #ifdef _CORY_TESTING
  87. FFSAVE_GEOMETRY = 8,
  88. #endif
  89. FFSAVE_XML = 9,
  90. FFSAVE_COLLADA = 10,
  91. FFSAVE_RAW = 11,
  92. FFSAVE_J2C = 12,
  93. FFSAVE_PNG = 13,
  94. FFSAVE_JPEG = 14,
  95. FFSAVE_SCRIPT = 15,
  96. };
  97. // open the dialog. This is a modal operation
  98. BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const std::string& filename = LLStringUtil::null );
  99. BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL, bool blocking = true );
  100. BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL );
  101. // Get the filename(s) found. getFirstFile() sets the pointer to
  102. // the start of the structure and allows the start of iteration.
  103. const std::string getFirstFile();
  104. // getNextFile() increments the internal representation and
  105. // returns the next file specified by the user. Returns NULL when
  106. // no more files are left. Further calls to getNextFile() are
  107. // undefined.
  108. const std::string getNextFile();
  109. // This utility function extracts the current file name without
  110. // doing any incrementing.
  111. const std::string getCurFile();
  112. // Returns the index of the current file.
  113. S32 getCurFileNum() const { return mCurrentFile; }
  114. S32 getFileCount() const { return (S32)mFiles.size(); }
  115. // See llvfs/lldir.h : getBaseFileName and getDirName to extract base or directory names
  116. // clear any lists of buffers or whatever, and make sure the file
  117. // picker isn't locked.
  118. void reset();
  119. private:
  120. enum
  121. {
  122. SINGLE_FILENAME_BUFFER_SIZE = 1024,
  123. //FILENAME_BUFFER_SIZE = 65536
  124. FILENAME_BUFFER_SIZE = 65000
  125. };
  126. // utility function to check if access to local file system via file browser
  127. // is enabled and if not, tidy up and indicate we're not allowed to do this.
  128. bool check_local_file_access_enabled();
  129. #if LL_WINDOWS
  130. OPENFILENAMEW mOFN; // for open and save dialogs
  131. WCHAR mFilesW[FILENAME_BUFFER_SIZE];
  132. BOOL setupFilter(ELoadFilter filter);
  133. #endif
  134. #if LL_DARWIN
  135. NavDialogCreationOptions mNavOptions;
  136. std::vector<std::string> mFileVector;
  137. UInt32 mFileIndex;
  138. OSStatus doNavChooseDialog(ELoadFilter filter);
  139. OSStatus doNavSaveDialog(ESaveFilter filter, const std::string& filename);
  140. void getFilePath(SInt32 index);
  141. void getFileName(SInt32 index);
  142. static Boolean navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode);
  143. #endif
  144. #if LL_GTK
  145. static void add_to_selectedfiles(gpointer data, gpointer user_data);
  146. static void chooser_responder(GtkWidget *widget, gint response, gpointer user_data);
  147. // we remember the last path that was accessed for a particular usage
  148. std::map <std::string, std::string> mContextToPathMap;
  149. std::string mCurContextName;
  150. #endif
  151. std::vector<std::string> mFiles;
  152. S32 mCurrentFile;
  153. bool mLocked;
  154. static LLFilePicker sInstance;
  155. protected:
  156. #if LL_GTK
  157. GtkWindow* buildFilePicker(bool is_save, bool is_folder,
  158. std::string context = "generic");
  159. #endif
  160. public:
  161. // don't call these directly please.
  162. LLFilePicker();
  163. ~LLFilePicker();
  164. };
  165. const std::string upload_pick(void* data);
  166. #endif