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,2006 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.31 2006/01/22 17:58:01 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; 1=cd, 2=term 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 [ ';' flags ] 00063 * 00064 * For example, the binding for "jpg" could be: 00065 * 00066 * xv %s &;JPEG Image;bigimage.xpm;miniimage.xpm;image/jpeg;term 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 * The flags field is used for a number of bit-flags; two flags are currently 00081 * defined: 'cd' and 'term'. The first one is intended to cause a launcher 00082 * to execute the application in the shown directory; the second one is meant 00083 * to indicate that the application is to be ran inside a new terminal. 00084 */ 00085 class FXAPI FXFileDict : public FXDict { 00086 FXDECLARE(FXFileDict) 00087 private: 00088 FXSettings *settings; // Settings database where to get bindings 00089 FXIconDict *icons; // Icon dictionary which keeps track of loaded icons 00090 protected: 00091 FXFileDict(){} 00092 virtual void *createData(const void*); 00093 virtual void deleteData(void*); 00094 private: 00095 FXFileDict(const FXFileDict&); 00096 FXFileDict &operator=(const FXFileDict&); 00097 public: 00098 00099 /// Registry key used to find fallback executable icons 00100 static const FXchar defaultExecBinding[]; 00101 00102 /// Registry key used to find fallback directory icons 00103 static const FXchar defaultDirBinding[]; 00104 00105 /// Registry key used to find fallback document icons 00106 static const FXchar defaultFileBinding[]; 00107 00108 public: 00109 00110 /** 00111 * Construct a dictionary mapping file-extension to file associations, 00112 * using the application registry settings as a source for the bindings. 00113 * The pointer to the application class is passed down to the icon source 00114 * which is inside the icon dictionary. 00115 */ 00116 FXFileDict(FXApp* app); 00117 00118 /** 00119 * Construct a dictionary mapping file-extension to file associations, 00120 * using the specified settings database as a source for the bindings. 00121 * The pointer to the application class is passed down to the icon source 00122 * which is inside the icon dictionary. 00123 */ 00124 FXFileDict(FXApp* app,FXSettings* db); 00125 00126 /// Change settings database 00127 void setSettings(FXSettings* s){ settings=s; } 00128 00129 /// Return settings database 00130 FXSettings* getSettings() const { return settings; } 00131 00132 /// Change icon dictionary 00133 void setIconDict(FXIconDict *icns){ icons=icns; } 00134 00135 /// Return icon dictionary 00136 FXIconDict* getIconDict() const { return icons; } 00137 00138 /** 00139 * Set icon search path; the initial search path is determined by the 00140 * "iconpath" registry setting in the SETTINGS section. 00141 */ 00142 void setIconPath(const FXString& path); 00143 00144 /// Return current icon search path 00145 const FXString& getIconPath() const; 00146 00147 /** 00148 * Replace file association. 00149 * The new association is written into the settings database under the 00150 * FILETYPES section; the format of the association is as follows: 00151 * 00152 * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>" 00153 * 00154 * Where <command> is the command used to launch the application (e.g. "xv %s &"), 00155 * and <type> is the file type string (e.g. "GIF Image"), 00156 * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode, 00157 * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode, 00158 * and <mimetype> is the RFC2045 mime type of the file. 00159 * 00160 * For example: 00161 * 00162 * [FILETYPES] 00163 * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif" 00164 * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder" 00165 * 00166 */ 00167 FXFileAssoc* replace(const FXchar* ext,const FXchar* str); 00168 00169 /// Remove file association 00170 FXFileAssoc* remove(const FXchar* ext); 00171 00172 /// Find file association from registry 00173 FXFileAssoc* find(const FXchar* ext); 00174 00175 /** 00176 * Determine binding for the given file. 00177 * The default implementation tries the whole filename first, 00178 * then tries the extensions. 00179 * For example, for a file "source.tar.gz": 00180 * 00181 * "source.tar.gz", 00182 * "tar.gz", 00183 * "gz" 00184 * 00185 * are tried in succession. If no association is found the 00186 * key "defaultfilebinding" is tried as a fallback association. 00187 * A NULL is returned if no association of any kind is found. 00188 */ 00189 virtual FXFileAssoc* findFileBinding(const FXchar* pathname); 00190 00191 /** 00192 * Find directory binding from registry. 00193 * The default implementation tries the whole pathname first, 00194 * then tries successively smaller parts of the path. 00195 * For example, a pathname "/usr/people/jeroen": 00196 * 00197 * "/usr/people/jeroen" 00198 * "/people/jeroen" 00199 * "/jeroen" 00200 * 00201 * are tried in succession. If no bindings are found, the 00202 * key "defaultdirbinding" is tried as a fallback association. 00203 * A NULL is returned if no association of any kind is found. 00204 */ 00205 virtual FXFileAssoc* findDirBinding(const FXchar* pathname); 00206 00207 /** 00208 * Determine binding for the given executable. 00209 * The default implementation returns the fallback binding associated with 00210 * the key "defaultexecbinding". 00211 * A NULL is returned if no association of any kind is found. 00212 */ 00213 virtual FXFileAssoc* findExecBinding(const FXchar* pathname); 00214 00215 /// Save to stream 00216 virtual void save(FXStream& store) const; 00217 00218 /// Load from stream 00219 virtual void load(FXStream& store); 00220 00221 /// Destructor 00222 virtual ~FXFileDict(); 00223 }; 00224 00225 } 00226 00227 #endif
Copyright © 1997-2005 Jeroen van der Zijp |