Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * F i l e - A s s o c i a t i o n T a b l e * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2005 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXFileDict.h,v 1.26 2005/02/05 06:56:08 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXFILEDICT_H 00025 #define FXFILEDICT_H 00026 00027 #ifndef FXDICT_H 00028 #include "FXDict.h" 00029 #endif 00030 00031 namespace FX { 00032 00033 00034 class FXIconDict; 00035 00036 00037 /// Registers stuff to know about the extension 00038 struct FXFileAssoc { 00039 FXString command; /// Command to execute 00040 FXString extension; /// Full extension name 00041 FXString mimetype; /// Mime type name 00042 FXIcon *bigicon; /// Big normal icon 00043 FXIcon *bigiconopen; /// Big open icon 00044 FXIcon *miniicon; /// Mini normal icon 00045 FXIcon *miniiconopen; /// Mini open icon 00046 FXDragType dragtype; /// Registered drag type 00047 FXuint flags; /// Flags 00048 }; 00049 00050 00051 00052 /** 00053 * The File Association dictionary associates a file extension with a File 00054 * Association record which contains command name, mime type, icons, and other 00055 * information about the file type. The icons referenced by the file association 00056 * are managed by the Icon Dictionary; this guarantees that each icon is loaded 00057 * only once into memory. 00058 * The associations are determined by the information by the FOX Registry settings; 00059 * each entry under the FILETYPES registry section comprises the command line, 00060 * extension name, large icon, small icon, and mime type: 00061 * 00062 * command ';' extension ';' bigicon [ ':' bigiconopen ] ';' icon [ ':' iconopen ] ';' mime 00063 * 00064 * For example, the binding for "jpg" could be: 00065 * 00066 * xv %s &;JPEG Image;bigimage.xpm;miniimage.xpm;image/jpeg 00067 * 00068 * The association for a file name is determined by first looking at the entire 00069 * file name, then at the whole extension, and then at sub-extensions. 00070 * For example, "name.tar.gz", "tar.gz", and "gz" can each be given a different 00071 * file association. Directory names may also be given associations; there is 00072 * no command-line association for a directory, however. The association for a 00073 * directory is found by first checking the whole pathname, then checking the 00074 * pathname less the first component, and so on. So, "/usr/local/include", 00075 * "/local/include", and "/include" can each be given their own file associations. 00076 * If the above lookup procedure has not found a file association, the system 00077 * uses a fallback associations: for files, the fallback association is determined 00078 * by the binding "defaultfilebinding". For directories, the "defaultdirbinding" 00079 * is used, and for executables the "defaultexecbinding" is used. 00080 */ 00081 class FXAPI FXFileDict : public FXDict { 00082 FXDECLARE(FXFileDict) 00083 private: 00084 FXSettings *settings; // Settings database where to get bindings 00085 FXIconDict *icons; // Icon dictionary which keeps track of loaded icons 00086 protected: 00087 FXFileDict(){} 00088 virtual void *createData(const void*); 00089 virtual void deleteData(void*); 00090 private: 00091 FXFileDict(const FXFileDict&); 00092 FXFileDict &operator=(const FXFileDict&); 00093 public: 00094 00095 /// Registry key used to find fallback executable icons 00096 static const FXchar defaultExecBinding[]; 00097 00098 /// Registry key used to find fallback directory icons 00099 static const FXchar defaultDirBinding[]; 00100 00101 /// Registry key used to find fallback document icons 00102 static const FXchar defaultFileBinding[]; 00103 00104 public: 00105 00106 /** 00107 * Construct a dictionary mapping file-extension to file associations, 00108 * using the application registry settings as a source for the bindings. 00109 * The pointer to the application class is passed down to the icon source 00110 * which is inside the icon dictionary. 00111 */ 00112 FXFileDict(FXApp* app); 00113 00114 /** 00115 * Construct a dictionary mapping file-extension to file associations, 00116 * using the specified settings database as a source for the bindings. 00117 * The pointer to the application class is passed down to the icon source 00118 * which is inside the icon dictionary. 00119 */ 00120 FXFileDict(FXApp* app,FXSettings* db); 00121 00122 /// Change icon dictionary 00123 void setIconDict(FXIconDict *icns){ icons=icns; } 00124 00125 /// Return icon dictionary 00126 FXIconDict* getIconDict() const { return icons; } 00127 00128 /** 00129 * Set icon search path; the initial search path is determined by the 00130 * "iconpath" registry setting in the SETTINGS section. 00131 */ 00132 void setIconPath(const FXString& path); 00133 00134 /// Return current icon search path 00135 const FXString& getIconPath() const; 00136 00137 /** 00138 * Replace file association. 00139 * The new association is written into the settings database under the 00140 * FILETYPES section; the format of the association is as follows: 00141 * 00142 * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>" 00143 * 00144 * Where <command> is the command used to launch the application (e.g. "xv %s &"), 00145 * and <type> is the file type string (e.g. "GIF Image"), 00146 * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode, 00147 * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode, 00148 * and <mimetype> is the RFC2045 mime type of the file. 00149 * 00150 * For example: 00151 * 00152 * [FILETYPES] 00153 * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif" 00154 * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder" 00155 * 00156 */ 00157 FXFileAssoc* replace(const FXchar* ext,const FXchar* str); 00158 00159 /// Remove file association 00160 FXFileAssoc* remove(const FXchar* ext); 00161 00162 /// Find file association already in dictionary 00163 FXFileAssoc* find(const FXchar* ext){ return (FXFileAssoc*)FXDict::find(ext); } 00164 00165 /// Find file association from registry 00166 FXFileAssoc* associate(const FXchar* key); 00167 00168 /** 00169 * Determine binding for the given file. 00170 * The default implementation tries the whole filename first, 00171 * then tries the extensions. 00172 * For example, for a file "source.tar.gz": 00173 * 00174 * "source.tar.gz", 00175 * "tar.gz", 00176 * "gz" 00177 * 00178 * are tried in succession. If no association is found the 00179 * key "defaultfilebinding" is tried as a fallback association. 00180 * A NULL is returned if no association of any kind is found. 00181 */ 00182 virtual FXFileAssoc* findFileBinding(const FXchar* pathname); 00183 00184 /** 00185 * Find directory binding from registry. 00186 * The default implementation tries the whole pathname first, 00187 * then tries successively smaller parts of the path. 00188 * For example, a pathname "/usr/people/jeroen": 00189 * 00190 * "/usr/people/jeroen" 00191 * "/people/jeroen" 00192 * "/jeroen" 00193 * 00194 * are tried in succession. If no bindings are found, the 00195 * key "defaultdirbinding" is tried as a fallback association. 00196 * A NULL is returned if no association of any kind is found. 00197 */ 00198 virtual FXFileAssoc* findDirBinding(const FXchar* pathname); 00199 00200 /** 00201 * Determine binding for the given executable. 00202 * The default implementation returns the fallback binding associated with 00203 * the key "defaultexecbinding". 00204 * A NULL is returned if no association of any kind is found. 00205 */ 00206 virtual FXFileAssoc* findExecBinding(const FXchar* pathname); 00207 00208 /// Save to stream 00209 virtual void save(FXStream& store) const; 00210 00211 /// Load from stream 00212 virtual void load(FXStream& store); 00213 00214 /// Destructor 00215 virtual ~FXFileDict(); 00216 }; 00217 00218 } 00219 00220 #endif
Copyright © 1997-2005 Jeroen van der Zijp |