Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXFileDict.h

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,2004 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.21 2004/02/08 17:17:33 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 /// Registers stuff to know about the extension 00035 struct FXFileAssoc { 00036 FXString command; /// Command to execute 00037 FXString extension; /// Full extension name 00038 FXString mimetype; /// Mime type name 00039 FXIcon *bigicon; /// Big normal icon 00040 FXIcon *bigiconopen; /// Big open icon 00041 FXIcon *miniicon; /// Mini normal icon 00042 FXIcon *miniiconopen; /// Mini open icon 00043 FXDragType dragtype; /// Registered drag type 00044 FXuint flags; /// Flags 00045 }; 00046 00047 00048 /// Icon dictionary 00049 class FXAPI FXIconDict : public FXDict { 00050 FXDECLARE(FXIconDict) 00051 private: 00052 FXApp *app; // Application object 00053 FXString path; // Where to search icons 00054 protected: 00055 FXIconDict(){} 00056 virtual void *createData(const void*); 00057 virtual void deleteData(void*); 00058 private: 00059 FXIconDict(const FXIconDict&); 00060 FXIconDict &operator=(const FXIconDict&); 00061 public: 00062 00063 /// Default icon search path 00064 static const FXchar defaultIconPath[]; 00065 00066 public: 00067 00068 /// Construct an icon dictionary, with given path 00069 FXIconDict(FXApp* a,const FXString& p=defaultIconPath); 00070 00071 /// Get application 00072 FXApp* getApp() const { return app; } 00073 00074 /// Set icon search path 00075 void setIconPath(const FXString& p){ path=p; } 00076 00077 /// Return current icon search path 00078 FXString getIconPath() const { return path; } 00079 00080 /// Insert unique icon loaded from filename into dictionary 00081 FXIcon* insert(const FXchar* name){ return (FXIcon*)FXDict::insert(name,name); } 00082 00083 /// Remove icon from dictionary 00084 FXIcon* remove(const FXchar* name){ return (FXIcon*)FXDict::remove(name); } 00085 00086 /// Find icon by name 00087 FXIcon* find(const FXchar* name){ return (FXIcon*)FXDict::find(name); } 00088 00089 /// Save to stream 00090 virtual void save(FXStream& store) const; 00091 00092 /// Load from stream 00093 virtual void load(FXStream& store); 00094 00095 /// Destructor 00096 virtual ~FXIconDict(); 00097 }; 00098 00099 00100 /** 00101 * The File Association dictionary associates a file extension 00102 * with a FXFileAssoc record which contains command name, mime type, 00103 * icons, and other information about the file type. 00104 * The Registry is used as source of the file bindings; an alternative 00105 * Settings database may be specified however. 00106 */ 00107 class FXAPI FXFileDict : public FXDict { 00108 FXDECLARE(FXFileDict) 00109 private: 00110 FXApp *app; // Application object 00111 FXSettings *settings; // Settings database where to get bindings 00112 FXIconDict *icons; // Icon table 00113 protected: 00114 FXFileDict(){} 00115 virtual void *createData(const void*); 00116 virtual void deleteData(void*); 00117 private: 00118 FXFileDict(const FXFileDict&); 00119 FXFileDict &operator=(const FXFileDict&); 00120 public: 00121 00122 /// Registry key used to find fallback executable icons 00123 static const FXchar defaultExecBinding[]; 00124 00125 /// Registry key used to find fallback directory icons 00126 static const FXchar defaultDirBinding[]; 00127 00128 /// Registry key used to find fallback document icons 00129 static const FXchar defaultFileBinding[]; 00130 public: 00131 00132 /** 00133 * Construct a dictionary mapping file-extension to file associations, 00134 * using the application registry settings as a source for the bindings. 00135 */ 00136 FXFileDict(FXApp* a); 00137 00138 /** 00139 * Construct a dictionary mapping file-extension to file associations, 00140 * using the specified settings database as a source for the bindings. 00141 */ 00142 FXFileDict(FXApp* a,FXSettings* db); 00143 00144 /// Get application 00145 FXApp* getApp() const { return app; } 00146 00147 /// Set icon search path 00148 void setIconPath(const FXString& path); 00149 00150 /// Return current icon search path 00151 FXString getIconPath() const; 00152 00153 /** 00154 * Replace file association. 00155 * The new association is written into the settings database under the 00156 * FILETYPES section; the format of the association is as follows: 00157 * 00158 * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>" 00159 * 00160 * Where <command> is the command used to launch the application (e.g. "xv %s &"), 00161 * and <type> is the file type string (e.g. "GIF Image"), 00162 * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode, 00163 * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode, 00164 * and <mimetype> is the RFC2045 mime type of the file. 00165 * 00166 * For example: 00167 * 00168 * [FILETYPES] 00169 * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif" 00170 * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder" 00171 * 00172 */ 00173 FXFileAssoc* replace(const FXchar* ext,const FXchar* str); 00174 00175 /// Remove file association 00176 FXFileAssoc* remove(const FXchar* ext); 00177 00178 /// Find file association already in dictionary 00179 FXFileAssoc* find(const FXchar* ext){ return (FXFileAssoc*)FXDict::find(ext); } 00180 00181 /// Find file association from registry 00182 FXFileAssoc* associate(const FXchar* key); 00183 00184 /** 00185 * Determine binding for the given file. 00186 * The default implementation tries the whole filename first, 00187 * then tries the extensions. 00188 * For example, for a file "source.tar.gz": 00189 * 00190 * "source.tar.gz", 00191 * "tar.gz", 00192 * "gz" 00193 * 00194 * are tried in succession. If no association is found the 00195 * key "defaultfilebinding" is tried as a fallback association. 00196 * A NULL is returned if no association of any kind is found. 00197 */ 00198 virtual FXFileAssoc* findFileBinding(const FXchar* pathname); 00199 00200 /** 00201 * Find directory binding from registry. 00202 * The default implementation tries the whole pathname first, 00203 * then tries successively smaller parts of the path. 00204 * For example, a pathname "/usr/people/jeroen": 00205 * 00206 * "/usr/people/jeroen" 00207 * "/people/jeroen" 00208 * "/jeroen" 00209 * 00210 * are tried in succession. If no bindings are found, the 00211 * key "defaultdirbinding" is tried as a fallback association. 00212 * A NULL is returned if no association of any kind is found. 00213 */ 00214 virtual FXFileAssoc* findDirBinding(const FXchar* pathname); 00215 00216 /** 00217 * Determine binding for the given executable. 00218 * The default implementation returns the fallback binding associated with 00219 * the key "defaultexecbinding". 00220 * A NULL is returned if no association of any kind is found. 00221 */ 00222 virtual FXFileAssoc* findExecBinding(const FXchar* pathname); 00223 00224 /// Save to stream 00225 virtual void save(FXStream& store) const; 00226 00227 /// Load from stream 00228 virtual void load(FXStream& store); 00229 00230 /// Destructor 00231 virtual ~FXFileDict(); 00232 }; 00233 00234 } 00235 00236 #endif

Copyright © 1997-2004 Jeroen van der Zijp