1 //------------------------------------------------------------------------------ 2 // emFpPlugin.h 3 // 4 // Copyright (C) 2006-2008,2010,2014,2018 Oliver Hamann. 5 // 6 // Homepage: http://eaglemode.sourceforge.net/ 7 // 8 // This program is free software: you can redistribute it and/or modify it under 9 // the terms of the GNU General Public License version 3 as published by the 10 // Free Software Foundation. 11 // 12 // This program is distributed in the hope that it will be useful, but WITHOUT 13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for 15 // more details. 16 // 17 // You should have received a copy of the GNU General Public License version 3 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. 19 //------------------------------------------------------------------------------ 20 21 #ifndef emFpPlugin_h 22 #define emFpPlugin_h 23 24 #ifndef emPanel_h 25 #include <emCore/emPanel.h> 26 #endif 27 28 29 //============================================================================== 30 //================================= emFpPlugin ================================= 31 //============================================================================== 32 33 class emFpPlugin : public emStructRec { 34 35 public: 36 37 // Record class for a file panel plugin. Such a plugin is able to create 38 // a panel for showing (and maybe editing) a file. An instance of this 39 // record class holds the configuration of such a plugin. It is usually 40 // loaded from a configuration file (see emFpPluginList). 41 42 emFpPlugin(); 43 // Construct empty. 44 45 virtual ~emFpPlugin(); 46 // Destructor. 47 48 49 // - - - - - Member Records - - - - - 50 51 emTArrayRec<emStringRec> FileTypes; 52 // Array of file types the plugin is able to handle. Each entry 53 // must be a file name suffix including the leading dot, or the 54 // special string "file" for accepting all regular files, or the 55 // special string "directory" for accepting directories. 56 57 emDoubleRec Priority; 58 // Priority of the plugin. If there are two plugins able to 59 // handle a file, the one with the higher priority is taken 60 // first. 61 62 emStringRec Library; 63 // Name of the dynamic library containing the plugin function 64 // (just the pure name, read comments on emTryOpenLib). 65 66 emStringRec Function; 67 // Name of the plugin function. It must match the interface 68 // defined by emFpPluginFunc. 69 70 class PropertyRec : public emStructRec { 71 public: 72 PropertyRec(); 73 virtual ~PropertyRec(); 74 emStringRec Name; 75 emStringRec Value; 76 }; 77 emTArrayRec<PropertyRec> Properties; 78 // Any number of plugin-defined properties in form of name/value 79 // pairs. 80 81 // - - - - - End of Member Records - - - - - 82 83 84 PropertyRec * GetProperty(const char * name); 85 // Search for a plugin-defined property. Returns NULL if not 86 // found. 87 88 emPanel * TryCreateFilePanel( 89 emPanel::ParentArg parent, const emString & name, 90 const emString & path 91 ); 92 // Create a file panel via this plugin. 93 // Arguments: 94 // parent - Parent of the panel. 95 // name - Name of the panel. 96 // path - Path name of the file to be shown. 97 // Returns: The created panel. 98 // Throws: An error message on failure. 99 100 virtual const char * GetFormatName() const; 101 // The file format name of this record file format. 102 103 private: 104 void * CachedFunc; 105 emString CachedFuncLib; 106 emString CachedFuncName; 107 }; 108 109 110 //============================================================================== 111 //=============================== emFpPluginFunc =============================== 112 //============================================================================== 113 114 115 extern "C" { 116 typedef emPanel * (*emFpPluginFunc) ( 117 emPanel::ParentArg parent, const emString & name, 118 const emString & path, emFpPlugin * plugin, 119 emString * errorBuf 120 ); 121 // Type of the plugin function of an emFpPlugin. Such a function 122 // creates a panel for showing a file. 123 // Arguments: 124 // parent - Parent of the panel. 125 // name - Name of the panel. 126 // path - Path name of the file to be shown. 127 // plugin - The plugin record (mainly for reading the 128 // plugin-defined properties). 129 // errorBuf - For returning an error message on failure. 130 // Returns: The created panel, or NULL on failure. 131 } 132 133 134 //============================================================================== 135 //=============================== emFpPluginList =============================== 136 //============================================================================== 137 138 class emFpPluginList : public emModel { 139 140 public: 141 142 // Class for a model containing a list of all the configured file panel 143 // plugins. The plugin configurations are loaded from a certain 144 // directory. 145 146 static emRef<emFpPluginList> Acquire(emRootContext & rootContext); 147 // Acquire the emFpPluginList. 148 149 emPanel * CreateFilePanel( 150 emPanel::ParentArg parent, const emString & name, 151 const emString & path, int alternative=0 152 ); 153 // Create a panel for a file. This calls the appropriate plugin. 154 // On failure, a panel showing the error message is created. 155 // Arguments: 156 // parent - Parent of the panel. 157 // name - Name of the panel. 158 // path - Path name of the file to be shown. 159 // alternative - If there are multiple plugins able to show 160 // the file, the one with the highest priority 161 // is chosen if this argument is 0. If this 162 // argument is 1, the one with the 163 // second-highest priority is chosen, and so on. 164 // Returns: The created panel. 165 166 emPanel * CreateFilePanel( 167 emPanel::ParentArg parent, const emString & name, 168 const emString & absolutePath, int statErr, long statMode, 169 int alternative=0 170 ); 171 // This method exists for optimization. It's like above, but the 172 // caller knows more about the file. 173 // Arguments: 174 // parent - Parent of the panel. 175 // name - Name of the panel. 176 // absolutePath - Absolute path name of the file to be shown. 177 // statErr - Zero if calling stat on the file was 178 // successful, otherwise the resulting value of 179 // errno. 180 // statMode - st.st_mode from calling stat on the file. 181 // alternative - Like with the above method. 182 // Returns: The created panel. 183 184 protected: 185 186 emFpPluginList(emContext & context, const emString & name); 187 virtual ~emFpPluginList(); 188 189 private: 190 191 static int CmpReversePluginPriorities( 192 emFpPlugin * const * obj1, emFpPlugin * const * obj2, 193 void * context 194 ); 195 196 emArray<emFpPlugin*> Plugins; 197 // Sorted by descending priority, secondly by file name. 198 }; 199 200 201 #endif 202