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

FXFileDict.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * F i l e - A s s o c i a t i o n T a b l e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXFileDict.h,v 1.31 2006/01/22 17:58:01 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXFILEDICT_H
25 #define FXFILEDICT_H
26 
27 #ifndef FXDICT_H
28 #include "FXDict.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 class FXIconDict;
35 
36 
37 /// Registers stuff to know about the extension
38 struct FXFileAssoc {
39  FXString command; /// Command to execute
40  FXString extension; /// Full extension name
41  FXString mimetype; /// Mime type name
42  FXIcon *bigicon; /// Big normal icon
43  FXIcon *bigiconopen; /// Big open icon
44  FXIcon *miniicon; /// Mini normal icon
45  FXIcon *miniiconopen; /// Mini open icon
46  FXDragType dragtype; /// Registered drag type
47  FXuint flags; /// Flags; 1=cd, 2=term
48  };
49 
50 
51 
52 /**
53 * The File Association dictionary associates a file extension with a File
54 * Association record which contains command name, mime type, icons, and other
55 * information about the file type. The icons referenced by the file association
56 * are managed by the Icon Dictionary; this guarantees that each icon is loaded
57 * only once into memory.
58 * The associations are determined by the information by the FOX Registry settings;
59 * each entry under the FILETYPES registry section comprises the command line,
60 * extension name, large icon, small icon, and mime type:
61 *
62 * command ';' extension ';' bigicon [ ':' bigiconopen ] ';' icon [ ':' iconopen ] ';' mime [ ';' flags ]
63 *
64 * For example, the binding for "jpg" could be:
65 *
66 * xv %s &;JPEG Image;bigimage.xpm;miniimage.xpm;image/jpeg;term
67 *
68 * The association for a file name is determined by first looking at the entire
69 * file name, then at the whole extension, and then at sub-extensions.
70 * For example, "name.tar.gz", "tar.gz", and "gz" can each be given a different
71 * file association. Directory names may also be given associations; there is
72 * no command-line association for a directory, however. The association for a
73 * directory is found by first checking the whole pathname, then checking the
74 * pathname less the first component, and so on. So, "/usr/local/include",
75 * "/local/include", and "/include" can each be given their own file associations.
76 * If the above lookup procedure has not found a file association, the system
77 * uses a fallback associations: for files, the fallback association is determined
78 * by the binding "defaultfilebinding". For directories, the "defaultdirbinding"
79 * is used, and for executables the "defaultexecbinding" is used.
80 * The flags field is used for a number of bit-flags; two flags are currently
81 * defined: 'cd' and 'term'. The first one is intended to cause a launcher
82 * to execute the application in the shown directory; the second one is meant
83 * to indicate that the application is to be ran inside a new terminal.
84 */
85 class FXAPI FXFileDict : public FXDict {
87 private:
88  FXSettings *settings; // Settings database where to get bindings
89  FXIconDict *icons; // Icon dictionary which keeps track of loaded icons
90 protected:
91  FXFileDict(){}
92  virtual void *createData(const void*);
93  virtual void deleteData(void*);
94 private:
95  FXFileDict(const FXFileDict&);
96  FXFileDict &operator=(const FXFileDict&);
97 public:
98 
99  /// Registry key used to find fallback executable icons
100  static const FXchar defaultExecBinding[];
101 
102  /// Registry key used to find fallback directory icons
103  static const FXchar defaultDirBinding[];
104 
105  /// Registry key used to find fallback document icons
106  static const FXchar defaultFileBinding[];
107 
108 public:
109 
110  /**
111  * Construct a dictionary mapping file-extension to file associations,
112  * using the application registry settings as a source for the bindings.
113  * The pointer to the application class is passed down to the icon source
114  * which is inside the icon dictionary.
115  */
116  FXFileDict(FXApp* app);
118  /**
119  * Construct a dictionary mapping file-extension to file associations,
120  * using the specified settings database as a source for the bindings.
121  * The pointer to the application class is passed down to the icon source
122  * which is inside the icon dictionary.
123  */
124  FXFileDict(FXApp* app,FXSettings* db);
125 
126  /// Change settings database
127  void setSettings(FXSettings* s){ settings=s; }
128 
129  /// Return settings database
130  FXSettings* getSettings() const { return settings; }
131 
132  /// Change icon dictionary
133  void setIconDict(FXIconDict *icns){ icons=icns; }
134 
135  /// Return icon dictionary
136  FXIconDict* getIconDict() const { return icons; }
137 
138  /**
139  * Set icon search path; the initial search path is determined by the
140  * "iconpath" registry setting in the SETTINGS section.
141  */
142  void setIconPath(const FXString& path);
143 
144  /// Return current icon search path
145  const FXString& getIconPath() const;
146 
147  /**
148  * Replace file association.
149  * The new association is written into the settings database under the
150  * FILETYPES section; the format of the association is as follows:
151  *
152  * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>"
153  *
154  * Where <command> is the command used to launch the application (e.g. "xv %s &"),
155  * and <type> is the file type string (e.g. "GIF Image"),
156  * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode,
157  * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode,
158  * and <mimetype> is the RFC2045 mime type of the file.
159  *
160  * For example:
161  *
162  * [FILETYPES]
163  * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif"
164  * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder"
165  *
166  */
167  FXFileAssoc* replace(const FXchar* ext,const FXchar* str);
168 
169  /// Remove file association
170  FXFileAssoc* remove(const FXchar* ext);
171 
172  /// Find file association from registry
173  FXFileAssoc* find(const FXchar* ext);
174 
175  /**
176  * Determine binding for the given file.
177  * The default implementation tries the whole filename first,
178  * then tries the extensions.
179  * For example, for a file "source.tar.gz":
180  *
181  * "source.tar.gz",
182  * "tar.gz",
183  * "gz"
184  *
185  * are tried in succession. If no association is found the
186  * key "defaultfilebinding" is tried as a fallback association.
187  * A NULL is returned if no association of any kind is found.
188  */
189  virtual FXFileAssoc* findFileBinding(const FXchar* pathname);
190 
191  /**
192  * Find directory binding from registry.
193  * The default implementation tries the whole pathname first,
194  * then tries successively smaller parts of the path.
195  * For example, a pathname "/usr/people/jeroen":
196  *
197  * "/usr/people/jeroen"
198  * "/people/jeroen"
199  * "/jeroen"
200  *
201  * are tried in succession. If no bindings are found, the
202  * key "defaultdirbinding" is tried as a fallback association.
203  * A NULL is returned if no association of any kind is found.
204  */
205  virtual FXFileAssoc* findDirBinding(const FXchar* pathname);
206 
207  /**
208  * Determine binding for the given executable.
209  * The default implementation returns the fallback binding associated with
210  * the key "defaultexecbinding".
211  * A NULL is returned if no association of any kind is found.
212  */
213  virtual FXFileAssoc* findExecBinding(const FXchar* pathname);
214 
215  /// Save to stream
216  virtual void save(FXStream& store) const;
217 
218  /// Load from stream
219  virtual void load(FXStream& store);
220 
221  /// Destructor
222  virtual ~FXFileDict();
223  };
224 
225 }
226 
227 #endif
char FXchar
Definition: fxdefs.h:380
Registers stuff to know about the extension.
Definition: FXFileDict.h:38
FXString mimetype
Full extension name.
Definition: FXFileDict.h:41
unsigned int FXuint
Definition: fxdefs.h:389
FXIcon * bigiconopen
Big normal icon.
Definition: FXFileDict.h:43
FXString command
Definition: FXFileDict.h:39
#define FXAPI
Definition: fxdefs.h:122
Application Object.
Definition: FXApp.h:158
The File Association dictionary associates a file extension with a File Association record which cont...
Definition: FXFileDict.h:85
The Settings class manages a key-value database.
Definition: FXSettings.h:44
FXString extension
Command to execute.
Definition: FXFileDict.h:40
Definition: FX4Splitter.h:31
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
FXIcon * miniicon
Big open icon.
Definition: FXFileDict.h:44
FXDragType dragtype
Mini open icon.
Definition: FXFileDict.h:46
The dictionary class maintains a fast-access hash table of entities indexed by a character string...
Definition: FXDict.h:41
The Icon Dictionary manages a collection of icons.
Definition: FXIconDict.h:50
FXIcon * bigicon
Mime type name.
Definition: FXFileDict.h:42
FXID FXDragType
Definition: fxdefs.h:454
FXIcon * miniiconopen
Mini normal icon.
Definition: FXFileDict.h:45
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXuint flags
Registered drag type.
Definition: FXFileDict.h:47
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp