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