00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __OP_OTLManager__
00020 #define __OP_OTLManager__
00021
00022 #include "OP_API.h"
00023 #include <UT/UT_IntArray.h>
00024 #include <UT/UT_StringArray.h>
00025 #include <UT/UT_SymbolTable.h>
00026 #include "OP_OTLLibrary.h"
00027 #include "OP_Operator.h"
00028
00029 class UT_WorkBuffer;
00030 class FS_IndexFile;
00031 class OP_Node;
00032 class OP_OperatorTable;
00033 class OP_OTLManagerSink;
00034 class OP_OTLManager;
00035
00036 #define OP_TYPEBARMODE_FULLMENU "fullmenu"
00037 #define OP_TYPEBARMODE_DISPLAYONLY "displayonly"
00038 #define OP_TYPEBARMODE_NONE "none"
00039
00040 class OP_API OP_OTLLoadCallback
00041 {
00042 public:
00043
00044 OP_OTLLoadCallback();
00045 virtual ~OP_OTLLoadCallback() {}
00046
00047 virtual bool onOTLLoadBegin(const char* otl_name, UT_String& error_message_out) = 0;
00048 };
00049
00050 class OP_API OP_OTLManager
00051 {
00052 public:
00053 OP_OTLManager();
00054 virtual ~OP_OTLManager();
00055
00056
00057 bool getSaveToHipFile() const;
00058 void setSaveToHipFile(bool savetohip);
00059 bool getSaveUnlockedToHipFile() const;
00060 void setSaveUnlockedToHipFile(bool saveunlockedtohip);
00061 bool getWarnOutOfDateOps() const;
00062 void setWarnOutOfDateOps(bool warn);
00063 bool getWarnDummyOpsOnLoad() const;
00064 void setWarnDummyOpsOnLoad(bool warn);
00065 bool getPreferLatestDate() const;
00066 void setPreferLatestDate(bool preferlatest);
00067 bool getPreferInternal() const;
00068 void setPreferInternal(bool preferinternal);
00069 bool getPreferIndexFile() const;
00070 void setPreferIndexFile(bool preferindexfile);
00071 bool getCreateBackups() const;
00072 void setCreateBackups(bool createbackups);
00073 bool getSafeguardOpDefs() const;
00074 void setSafeguardOpDefs(bool safeguardopdefs);
00075 bool getLeaveDefaultsUnchanged() const;
00076 void setLeaveDefaultsUnchanged(bool leavedefaultsunchanged);
00077 bool getUseOplibrariesFiles() const;
00078 void setUseOplibrariesFiles(bool useoplibrariesfiles);
00079 const UT_String &getOperatorTypeBarMode() const;
00080 void setOperatorTypeBarMode(const char *mode);
00081 const UT_StringArray&getAllowedOperatorTypeBarModes() const;
00082
00083
00084
00085 static void registerOTLLoadCallback(OP_OTLLoadCallback * cb);
00086
00087
00088 bool runOTLCallbacks(const char* otl_name, UT_String& error_out);
00089
00090
00091 UT_StringArray &getFailedOTLs();
00092
00093
00094 void clearFailedOTLList();
00095
00096
00097
00098
00099 bool loadOpLibrariesFile(UT_IStream &is,
00100 const char *metasrc, int &libpos);
00101
00102
00103
00104 bool saveInternalMetaFile(ostream &os,
00105 const char *prefix = 0) const;
00106
00107
00108
00109
00110
00111
00112
00113 void setLibraryPreference(const char *tablename,
00114 const char *opname,
00115 const char *libfile);
00116
00117
00118
00119
00120 void setLibraryPreferencesIfRequired(int index);
00121
00122
00123 const char *getLibraryPreference(const char *tablename,
00124 const char *opname) const;
00125
00126 void clearLibraryPreferences(bool refreshlibs);
00127
00128 bool loadLibraryPreferences(UT_IStream &is);
00129 void saveLibraryPreferences(ostream &os,
00130 bool includeinternal = true,
00131 bool protectstrings = false) const;
00132
00133
00134 const UT_String &getMetaSourceName(OP_OTLLibrary *lib,
00135 bool withpath = true) const;
00136 void getMetaSourceName(const char *metasrc,
00137 UT_String &metasrcname,
00138 bool withpath = true) const;
00139 bool setMetaSourceName(const char *metasrc,
00140 const char *metasrcname);
00141
00142
00143
00144
00145 bool getIsPerformingAtomicAddRemove() const;
00146
00147
00148
00149
00150 bool getIsPerformingRefreshAll() const;
00151
00152
00153 bool getIsCreatingNewHDA() const;
00154
00155
00156 void loadAutoOTLs();
00157 int findLibrary(const char *libfile,
00158 const char *metasrc = 0) const;
00159 int findNextLibrary(const char *libfile,
00160 int after) const;
00161 bool refreshLibrary(int index, bool force = true);
00162 bool removeLibrary(const char *libfile,
00163 const char *metasrc,
00164 bool changeoplibraries);
00165 bool removeMetaSource(const char *metasrc);
00166 void refreshAll(bool reloadOpLibraries);
00167
00168
00169
00170
00171
00172 OP_OTLLibrary *addLibrary(const char *libfile,
00173 const char *metasrc,
00174 bool changeoplibraries,
00175 bool installinternaliffail,
00176 UT_WorkBuffer &errors);
00177
00178
00179 int getNumLibraries() const;
00180 int getPreferredLibrary(const char *tablename,
00181 const char *opname);
00182 OP_OTLLibrary *getLibrary(int index) const;
00183
00184
00185
00186 int getLatestLibrary(const char *tablename,
00187 const char *opname,
00188 OP_OTLLibrary *tiegoesto = 0);
00189 bool getOutOfDateInternalOps(UT_StringArray &ops);
00190
00191
00192
00193 int getNextLibrary(const char *tablename,
00194 const char *opname,
00195 OP_OTLLibrary *startat);
00196
00197
00198
00199 bool addToLibrary(OP_OTLLibrary *lib,
00200 OP_OTLDefinition &definition,
00201 FS_IndexFile *deffile,
00202 bool dummydefinition = false) const;
00203 bool addToLibrary(const char *libfile,
00204 OP_OTLDefinition &definition,
00205 FS_IndexFile *deffile,
00206 bool dummydefinition = false);
00207
00208
00209
00210 bool mergeLibraries(const char *primary,
00211 const char *secondary);
00212
00213
00214
00215
00216
00217 bool addToInternalLibrary(OP_OTLLibrary *newlib);
00218 bool addToInternalLibrary(UT_IStream &is, int modtime);
00219
00220
00221
00222
00223 bool removeFromLibrary(const char *libfile,
00224 const UT_StringArray &ops);
00225
00226
00227
00228 bool touchDefinition(const char *libfile,
00229 const char *tablename,
00230 const char *opname,
00231 int newtime = -1);
00232
00233
00234
00235
00236 void modifyDefinitionToInternalPaths(
00237 OP_OTLDefinition &def,
00238 FS_IndexFile *deffile) const;
00239
00240
00241 void saveOpTypeFromNode( OP_Node *node, UT_String &errors );
00242
00243
00244
00245
00246 void updateContentsFromNode(FS_IndexFile *deffile,
00247 OP_Node *node,
00248 bool gzipcontents,
00249 bool compilebasic,
00250 bool compilevopnets,
00251 bool compilechannels,
00252 bool compilenodenames,
00253 const char *library);
00254
00255
00256 void updateDefinitionFromNode(FS_IndexFile *deffile,
00257 OP_Node *node,
00258 bool lockcontents,
00259 bool usedsparms,
00260 bool gzipcontents,
00261 bool savespareparms,
00262 bool compile_asset,
00263 const char *library);
00264
00265
00266 void setContentsCompression(FS_IndexFile *deffile,
00267 int gzipcontents);
00268
00269
00270 bool getComment(FS_IndexFile &deffile, UT_String &result);
00271 void setComment(FS_IndexFile *deffile, const char *comment);
00272 bool getVersion(FS_IndexFile &deffile, UT_String &result);
00273 void setVersion(FS_IndexFile *deffile, const char *version);
00274
00275
00276 void listLibraries(ostream &os) const;
00277 void listLibrariesWithDefinition(const char *tablename,
00278 const char *opname,
00279 ostream &os) const;
00280 void listOperators(const char *libfile, ostream &os) const;
00281 void listOperator(const char *libfile,
00282 const char *tablename,
00283 const char *opname,
00284 const char *format,
00285 ostream &os) const;
00286
00287
00288
00289 void getLibrariesWithDefinition(
00290 const char *tablename,
00291 const char *opname,
00292 UT_PtrArray<OP_OTLLibrary *> &list);
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 bool getAllMatchingOperators(const char *opmask,
00307 const OP_OTLLibrary *library,
00308 bool onlyotlops,
00309 UT_StringArray &results,
00310 UT_SymbolTable &resultstable) const;
00311
00312
00313 void addManagerSink(OP_OTLManagerSink *sink);
00314 void removeManagerSink(OP_OTLManagerSink *sink);
00315
00316
00317 bool checkValidNodeName(const char *name,
00318 OP_OperatorTable *table,
00319 UT_WorkBuffer &errors);
00320
00321 bool createOptype(const char *tablename,
00322 const char *opname,
00323 const char *oplabel,
00324 const char *installpath,
00325 int min, int max,
00326 const char *extradsinfo,
00327 const char *installmetasrc,
00328 const char *extrainfo,
00329 bool subnet,
00330 UT_WorkBuffer &errors);
00331
00332 static bool getHelpTemplateFile(UT_String &helptemplatefile);
00333 static void createDefaultOptypeName(OP_Node *fromnode,
00334 UT_String &name,
00335 UT_String &label);
00336 static void fullyQualifyLibFileName(const char *libfilebase,
00337 UT_String &libfile,
00338 const char *basedir = 0);
00339 void fullyQualifyMetaSrcName(const char *libfilebase,
00340 UT_String &libfile) const;
00341 void getSimplifiedPath(UT_String &destpath,
00342 const char *srcpath,
00343 const char *srcmeta) const;
00344
00345 bool canSavePreferences() const;
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 void pushFallbackLibraryContext();
00356 void popFallbackLibraryContext();
00357 void saveFallbackLibraryPaths(ostream &os,
00358 const OP_OperatorList &ops) const;
00359 bool loadFallbackLibraryPaths(UT_IStream &is);
00360 bool loadFallbackLibrary(const char *tablename,
00361 const char *opname);
00362
00363
00364
00365
00366
00367
00368
00369 void setDummyDefinition(const OP_OTLDefinition &definition,
00370 const FS_IndexFile *deffile);
00371 bool getDummyDefinition(const OP_Operator *op,
00372 FS_IndexFile *deffile) const;
00373 bool loadDummyDefinitions(UT_IStream &is, int modtime);
00374 void saveDummyDefinitions(ostream &os,
00375 const OP_OperatorList &ops) const;
00376
00377
00378 static void saveDefaultDialogScript(ostream &os,
00379 const char *opname,
00380 const char *oplabel,
00381 const char *extradsinfo);
00382
00383 static void saveDefaultCreationScript(ostream &os,
00384 const char *op,
00385 const char *table);
00386
00387
00388
00389
00390 void writeOutDefinitionContents(
00391 const OP_OTLDefinition &definition,
00392 FS_IndexFile & contents,
00393 ostream & os) const;
00394
00395
00396 void setFilters(const OP_OTLDefinition &definition,
00397 FS_IndexFile &contents) const;
00398
00399
00400
00401 void refreshLicenses();
00402
00403
00404
00405
00406
00407 const UT_String &getInternalTempFile() const;
00408
00409
00410
00411 bool hasNCAsset(const OP_OTLLibrary *lib);
00412
00413
00414
00415 void getNCAssets(const OP_OTLLibrary *lib,
00416 UT_IntArray & nc_assets);
00417
00418 private:
00419
00420 void notifySinksOfDefinitionsAdded(int libindex,
00421 UT_IntArray &defarray);
00422 void notifySinksOfDefinitionsRemoved(int libindex,
00423 UT_IntArray &defarray,
00424 OP_OTLLibrary *&preserve);
00425 void notifySinksOfSourceNamesChanged();
00426 void notifySinksOfLibraryAdded(OP_OTLLibrary *library);
00427 void notifySinksOfLibraryRemoved(OP_OTLLibrary *library);
00428 void notifySinksOfConfigurationChanged();
00429 void notifySinksOfLicensesChanged();
00430 void writeSimplifiedPath(ostream &os,
00431 const char *srcpath,
00432 const char *srcmeta,
00433 const char *prefix = 0) const;
00434
00435
00436 void setMetaSourceNameData(int pos, const char *metasrc,
00437 const char *metasrcname);
00438
00439
00440
00441
00442 bool saveMetaFile(const char *metafile,
00443 const char *skiplib,
00444 const char *addlib) const;
00445
00446
00447
00448 int addToMetaSource(const char *libfile,
00449 const char *metasrc,
00450 bool changeoplibraries);
00451
00452
00453 bool insertLibrary(OP_OTLLibrary *newlib, int before);
00454
00455 bool removeLibrary(int index);
00456
00457 void loadPreferences();
00458 void savePreferences();
00459
00460 void moveInternalToNewTempFile();
00461
00462
00463 void clearIfGoodDefinitionExists(OP_OTLLibrary *lib);
00464
00465 bool removeFromExternalLibrary(const char *libfile,
00466 const UT_StringArray &ops);
00467
00468
00469
00470 bool removeFromInternalLibrary(const UT_StringArray &ops);
00471
00472
00473
00474 bool touchExternalDefinition(const char *libfile,
00475 const char *tablename,
00476 const char *opname,
00477 int newtime);
00478 bool touchInternalDefinition(const char *tablename,
00479 const char *opname,
00480 int newtime);
00481
00482 void addFromOpLibrariesFile(const char *file,
00483 const char *metasrc,
00484 int &libpos);
00485
00486
00487 void setLibraryPreference(const char *tablename,
00488 const char *opname,
00489 const char *libfile,
00490 UT_IntArray *libstorefresh);
00491
00492
00493 void addFallbackLibraryPath(const char *tablename,
00494 const char *opname,
00495 const char *libfile);
00496 bool loadFallbackLibrary(UT_SymbolTable *context,
00497 const char *opsymbol,
00498 const char *tablename,
00499 const char *opname);
00500 void clearLibraryFallbacks(UT_SymbolTable *table);
00501
00502
00503 bool isNCAsset(FS_IndexFile * lib_file,
00504 const OP_OTLDefinition & def);
00505
00506
00507
00508
00509 static void deleteLibraries(void *data);
00510
00511 UT_PtrArray<OP_OTLLibrary *> myLibraries;
00512 UT_PtrArray<OP_OTLManagerSink *> myManagerSinks;
00513 UT_PtrArray<OP_OTLLibrary *> myLibrariesBeingRemoved;
00514 UT_String myInternalTempFile;
00515 UT_String myNewInternalTempFile;
00516 UT_StringArray myMetaSourcesWithNames;
00517 UT_StringArray myMetaSourceNames;
00518 UT_StringArray myMetaSourceNameWithPaths;
00519 UT_SymbolTable myLibraryPreferences;
00520 UT_PtrArray<UT_SymbolTable *> myLibraryFallbacks;
00521 OP_OTLLibrary myDummyDefinitions;
00522 UT_String myOperatorTypeBarMode;
00523 bool myIsPerformingAtomicAddRemove;
00524 bool myIsPerformingRefreshAll;
00525 bool mySaveToHipFile;
00526 bool mySaveUnlockedToHipFile;
00527 bool myWarnOutOfDateOps;
00528 bool myWarnDummyOpsOnLoad;
00529 bool myPreferLatestDateDefinition;
00530 bool myPreferInternalDefinition;
00531 bool myPreferIndexFileDefinition;
00532 bool myCreateBackups;
00533 bool mySafeguardOpDefs;
00534 bool myLeaveDefaultsUnchanged;
00535 bool myUseOplibrariesFiles;
00536 bool myIsCreatingNewHDA;
00537 static UT_PtrArray<OP_OTLLoadCallback *>
00538 theOTLLoadCallbacks;
00539 UT_StringArray myFailedOTLs;
00540 };
00541
00542 class OP_API OP_OTLManagerSink
00543 {
00544 public:
00545 OP_OTLManagerSink() { }
00546 virtual ~OP_OTLManagerSink()
00547 { removeAllManagerSinks(); }
00548
00549 virtual void definitionsAdded(int ,
00550 UT_IntArray & ) { }
00551 virtual void definitionsRemoved(int ,
00552 UT_IntArray & ,
00553 OP_OTLLibrary *& ){ }
00554 virtual void sourceNamesChanged() { }
00555 virtual void libraryAdded(OP_OTLLibrary * ) { }
00556 virtual void libraryRemoved(OP_OTLLibrary * ) { }
00557 virtual void configurationChanged() { }
00558 virtual void licensesChanged() { }
00559
00560 void managerDeleted(OP_OTLManager *manager)
00561 { removeManagerSink(manager); }
00562
00563 protected:
00564 void addManagerSink(OP_OTLManager *manager)
00565 {
00566 if( !manager ) return;
00567 manager->addManagerSink(this);
00568 myManagers.append(manager, 1);
00569 }
00570 void removeManagerSink(OP_OTLManager *manager)
00571 {
00572 if( !manager ) return;
00573 manager->removeManagerSink(this);
00574 myManagers.findAndRemove(manager);
00575 }
00576 void removeAllManagerSinks()
00577 {
00578 for( int i = myManagers.entries(); i --> 0; )
00579 removeManagerSink(myManagers(i));
00580 }
00581
00582 private:
00583 UT_PtrArray<OP_OTLManager *> myManagers;
00584 };
00585
00586 #endif
00587