PageRenderTime 94ms CodeModel.GetById 61ms app.highlight 10ms RepoModel.GetById 20ms app.codeStats 0ms

/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
 27// OS specific file selection dialog. This is implemented as a
 28// singleton class, so call the instance() method to get the working
 29// instance. When you call getMultipleOpenFile(), it locks the picker
 30// until you iterate to the end of the list of selected files with
 31// getNextFile() or call reset().
 32
 33#ifndef LL_LLFILEPICKER_H
 34#define LL_LLFILEPICKER_H
 35
 36#include "stdtypes.h"
 37
 38#if LL_DARWIN
 39#include <Carbon/Carbon.h>
 40
 41// AssertMacros.h does bad things.
 42#undef verify
 43#undef check
 44#undef require
 45
 46#include <vector>
 47#include "llstring.h"
 48
 49#endif
 50
 51// Need commdlg.h for OPENFILENAMEA
 52#ifdef LL_WINDOWS
 53#include <commdlg.h>
 54#endif
 55
 56extern "C" {
 57// mostly for Linux, possible on others
 58#if LL_GTK
 59# include "gtk/gtk.h"
 60#endif // LL_GTK
 61}
 62
 63class LLFilePicker
 64{
 65#ifdef LL_GTK
 66	friend class LLDirPicker;
 67	friend void chooser_responder(GtkWidget *, gint, gpointer);
 68#endif // LL_GTK
 69public:
 70	// calling this before main() is undefined
 71	static LLFilePicker& instance( void ) { return sInstance; }
 72
 73	enum ELoadFilter
 74	{
 75		FFLOAD_ALL = 1,
 76		FFLOAD_WAV = 2,
 77		FFLOAD_IMAGE = 3,
 78		FFLOAD_ANIM = 4,
 79#ifdef _CORY_TESTING
 80		FFLOAD_GEOMETRY = 5,
 81#endif
 82		FFLOAD_XML = 6,
 83		FFLOAD_SLOBJECT = 7,
 84		FFLOAD_RAW = 8,
 85		FFLOAD_MODEL = 9,
 86		FFLOAD_COLLADA = 10,
 87		FFLOAD_SCRIPT = 11,
 88	};
 89
 90	enum ESaveFilter
 91	{
 92		FFSAVE_ALL = 1,
 93		FFSAVE_WAV = 3,
 94		FFSAVE_TGA = 4,
 95		FFSAVE_BMP = 5,
 96		FFSAVE_AVI = 6,
 97		FFSAVE_ANIM = 7,
 98#ifdef _CORY_TESTING
 99		FFSAVE_GEOMETRY = 8,
100#endif
101		FFSAVE_XML = 9,
102		FFSAVE_COLLADA = 10,
103		FFSAVE_RAW = 11,
104		FFSAVE_J2C = 12,
105		FFSAVE_PNG = 13,
106		FFSAVE_JPEG = 14,
107		FFSAVE_SCRIPT = 15,
108	};
109
110	// open the dialog. This is a modal operation
111	BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const std::string& filename = LLStringUtil::null );
112	BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL, bool blocking = true  );
113	BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL );
114
115	// Get the filename(s) found. getFirstFile() sets the pointer to
116	// the start of the structure and allows the start of iteration.
117	const std::string getFirstFile();
118
119	// getNextFile() increments the internal representation and
120	// returns the next file specified by the user. Returns NULL when
121	// no more files are left. Further calls to getNextFile() are
122	// undefined.
123	const std::string getNextFile();
124
125	// This utility function extracts the current file name without
126	// doing any incrementing.
127	const std::string getCurFile();
128
129	// Returns the index of the current file.
130	S32 getCurFileNum() const { return mCurrentFile; }
131
132	S32 getFileCount() const { return (S32)mFiles.size(); }
133
134	// See llvfs/lldir.h : getBaseFileName and getDirName to extract base or directory names
135	
136	// clear any lists of buffers or whatever, and make sure the file
137	// picker isn't locked.
138	void reset();
139
140private:
141	enum
142	{
143		SINGLE_FILENAME_BUFFER_SIZE = 1024,
144		//FILENAME_BUFFER_SIZE = 65536
145		FILENAME_BUFFER_SIZE = 65000
146	};
147
148	// utility function to check if access to local file system via file browser 
149	// is enabled and if not, tidy up and indicate we're not allowed to do this.
150	bool check_local_file_access_enabled();
151	
152#if LL_WINDOWS
153	OPENFILENAMEW mOFN;				// for open and save dialogs
154	WCHAR mFilesW[FILENAME_BUFFER_SIZE];
155
156	BOOL setupFilter(ELoadFilter filter);
157#endif
158
159#if LL_DARWIN
160	NavDialogCreationOptions mNavOptions;
161	std::vector<std::string> mFileVector;
162	UInt32 mFileIndex;
163	
164	OSStatus doNavChooseDialog(ELoadFilter filter);
165	OSStatus doNavSaveDialog(ESaveFilter filter, const std::string& filename);
166	void getFilePath(SInt32 index);
167	void getFileName(SInt32 index);
168	static Boolean navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode);
169#endif
170
171#if LL_GTK
172	static void add_to_selectedfiles(gpointer data, gpointer user_data);
173	static void chooser_responder(GtkWidget *widget, gint response, gpointer user_data);
174	// we remember the last path that was accessed for a particular usage
175	std::map <std::string, std::string> mContextToPathMap;
176	std::string mCurContextName;
177#endif
178
179	std::vector<std::string> mFiles;
180	S32 mCurrentFile;
181	bool mLocked;
182
183	static LLFilePicker sInstance;
184	
185protected:
186#if LL_GTK
187        GtkWindow* buildFilePicker(bool is_save, bool is_folder,
188				   std::string context = "generic");
189#endif
190
191public:
192	// don't call these directly please.
193	LLFilePicker();
194	~LLFilePicker();
195};
196
197const std::string upload_pick(void* data);
198
199#endif