HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_GalleryDataSource.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SQL.h
7  *
8  * COMMENTS:
9  * Data source for QT_GalleryModel. Uses an abstract implementation class
10  * to do the real work. The implementation class comes from a plugin
11  * framework based onthe requested source identifier string.
12  */
13 
14 #ifndef __UT_GALLERYDATASOURCE_H__
15 #define __UT_GALLERYDATASOURCE_H__
16 
17 #include "UT_API.h"
18 #include "UT_Function.h"
19 #include "UT_GalleryTypes.h"
20 #include "UT_Map.h"
21 #include "UT_NonCopyable.h"
22 #include "UT_Options.h"
23 #include "UT_SharedPtr.h"
24 #include "UT_StringArray.h"
25 #include "UT_StringHolder.h"
26 #include "UT_StringSet.h"
27 #include "UT_WorkBuffer.h"
28 
29 #include <SYS/SYS_Compiler.h>
30 #include <SYS/SYS_Inline.h>
31 #include <SYS/SYS_Time.h>
32 
33 #include <time.h>
34 
36 
37 ///
38 /// Implementation class for UT_GalleryDataSource. Subclass this and register
39 /// it with UT_GalleryDataSource as a plugin to create a new data source.
40 /// See documentation for hou.AssetGalleryDataSource for descriptions of the
41 /// methods that need to be implemented to create a new DataSource subclass.
42 ///
44 {
45 public:
46  virtual ~UT_GalleryDataSourceImpl();
48 
49  ///
50  /// Required overrides
51  ///
52 
53  /// Check if the data source is valid. If not, no other methods will ever
54  /// be called on this object.
55  virtual bool isValid() const = 0;
56  /// If this method returns true, none of the set methods should ever be
57  /// called, or expected to do anything.
58  /// Exception: if this method returns true but supportsAnnotations()
59  /// also returns true, then some set methods will be called. These
60  /// are: setIsStarred, setColorTag, setMetadata, createTag, deleteTag,
61  /// addTag, removeTag.
62  virtual bool isReadOnly() const = 0;
63  /// Per-item equivalent of isReadOnly(), only relevant when
64  /// isReadOnly() is false. The exception documented on isReadOnly()
65  /// applies here too.
66  virtual bool isItemReadOnly(const UT_StringRef &item_id) const
67  { return false; }
68  /// Indicates whether annotations (stars, tags, etc) can be edited
69  /// even when the gallery item contents are read-only.
70  virtual bool supportsAnnotations() const
71  { return false; }
72  /// Return HTML formatted info about the data source.
73  virtual UT_StringHolder infoHtml() const = 0;
74 
75  /// Populate an array with all valid item ids.
76  virtual void itemIds(UT_StringArray &item_ids) const = 0;
77  virtual void updatedItemIds(UT_StringArray &item_ids) = 0;
78 
79  /// Populate an array with all valid item ids with the given parent 'item_id'. By default there is no hierarchy.
80  virtual void childItemIds(const UT_StringRef &parent_item_id, UT_StringArray &item_ids) const;
81 
82  /// A string identifying the implementation data type.
83  virtual UT_StringHolder sourceTypeName(
84  const UT_StringRef &item_id) const = 0;
85  virtual UT_StringHolder typeName(const UT_StringRef &item_id) const = 0;
86  virtual UT_StringHolder renderMethod(const UT_StringRef &item_id) const = 0;
87  virtual UT_StringHolder label(const UT_StringRef &item_id) const = 0;
88  virtual UT_WorkBuffer thumbnail(const UT_StringRef &item_id) const = 0;
89  /// Return a Qt resource path for an icon to display in tree view mode.
90  /// If empty, the gallery falls back to the item's thumbnail.
91  virtual UT_StringHolder treeIcon(const UT_StringRef &item_id) const
93  virtual time_t creationDate(const UT_StringRef &item_id) const = 0;
94  virtual time_t modificationDate(const UT_StringRef &item_id) const = 0;
95  virtual bool isStarred(const UT_StringRef &item_id) const = 0;
96  virtual UT_StringHolder colorTag(const UT_StringRef &item_id) const = 0;
97  virtual UT_StringSet tags(const UT_StringRef &item_id) const = 0;
98  virtual UT_Options metadata(const UT_StringRef &item_id) const = 0;
99  virtual UT_StringHolder filePath(const UT_StringRef &item_id) const = 0;
100  virtual bool ownsFile(const UT_StringRef &item_id) const = 0;
101  virtual UT_WorkBuffer blindData(const UT_StringRef &item_id) const = 0;
102  virtual UT_StringHolder status(const UT_StringRef &item_id) const = 0;
103  /// Return the parent item id of the given 'item_id'
104  virtual UT_StringHolder parentId(const UT_StringRef &item_id) const = 0;
105  virtual UT_StringHolder prepareItemForUse(const UT_StringRef &item_id) const = 0;
106 
107  ///
108  /// Required overrides for writable data sources
109  ///
110 
111  virtual bool setRenderMethod(const UT_StringRef &item_id,
112  const UT_StringHolder &render_method)
113  { return false; }
114  virtual bool setLabel(const UT_StringRef &item_id,
115  const UT_StringHolder &label)
116  { return false; }
117  virtual bool setThumbnail(const UT_StringRef &item_id,
118  const UT_WorkBuffer &thumbnail)
119  { return false; }
120  virtual bool setModificationDate(const UT_StringRef &item_id,
121  time_t timestamp)
122  { return false; }
123  virtual bool setIsStarred(const UT_StringRef &item_id,
124  bool isstarred)
125  { return false; }
126  virtual bool setColorTag(const UT_StringRef &item_id,
127  const UT_StringHolder &color_tag)
128  { return false; }
129  virtual bool setMetadata(const UT_StringRef &item_id,
130  const UT_Options &metadata)
131  { return false; }
132  virtual bool setFilePath(const UT_StringRef &item_id,
133  const char *file_path)
134  { return false; }
135  virtual bool setOwnsFile(const UT_StringRef &item_id,
136  bool owns_file)
137  { return false; }
138  virtual bool setBlindData(const UT_StringRef &item_id,
139  const void *data, int data_size)
140  { return false; }
141  virtual bool setStatus(const UT_StringRef &item_id,
142  const UT_StringHolder &status)
143  { return false; }
144  virtual bool setParentId(const UT_StringRef &item_id,
145  const UT_StringHolder &parent_item_id)
146  { return false; }
147 
148  virtual bool createTag(const char *tag)
149  { return false; }
150  virtual bool deleteTag(const char *tag, bool delete_if_assigned) const
151  { return false; }
152  virtual bool addTag(const UT_StringRef &item_id, const char *tag)
153  { return false; }
154  virtual bool removeTag(const UT_StringRef &item_id, const char *tag) const
155  { return false; }
156 
157  virtual bool isFilePathEditable(const UT_StringRef &item_id) const
158  { return true; }
159 
160  /// Generates a file path to associate with a particular item id, for
161  /// cases where the new item needs a new file, as in a snapshot data source
162  /// (rather than referring to an existing file, as in an asset data source).
164  const UT_StringRef &item_id,
165  const char *file_ext)
167 
168  /// Add a new gallery item to the data source.
169  virtual UT_StringHolder addItem(const UT_StringRef &item_type_name,
170  const UT_StringRef &name,
171  const void *thumbnail_data,
172  int thumbnail_data_size,
173  const char *item_file,
174  bool item_owns_file,
175  const void *item_data,
176  int item_data_size,
177  time_t *creation_date,
178  const UT_StringRef &parent_id)
180 
181  /// Mark items for deletion in the data source.
182  /// Do nothing for invalid item ids or items that are already
183  /// marked for deletion.
184  virtual bool markItemsForDeletion(const UT_StringArray &item_ids)
185  { return false; }
186  /// Unmark items for deletion in the data source.
187  /// Do nothing for invalid item ids or items that are not
188  /// marked for deletion.
189  virtual bool unmarkItemsForDeletion(const UT_StringArray &item_ids)
190  { return false; }
191 
192  ///
193  /// Optional overrides
194  ///
195 
196  virtual void startTransaction() const
197  { }
198  virtual void endTransaction(bool commit = true) const
199  { }
200 
201  /// For file-based sources, does the equivalent of a "save as" operation.
202  /// The source identifier of the data source should be updated if the
203  /// implementation's save as operation reports success.
204  virtual bool saveAs(const UT_StringHolder &source_identifier)
205  { return false; }
206 
207 protected:
209 
210  void addOwner(const UT_GalleryDataSource *owner)
211  { myOwnerUpdatedIds.emplace(owner, UT_StringSet()); }
213  { myOwnerUpdatedIds.erase(owner); }
214  void ownerFetchedUpdatedIds(const UT_GalleryDataSource *owner,
215  UT_StringArray &item_ids);
216 
218 
219  friend class UT_GalleryDataSource;
220 };
221 
222 ///
223 /// Provides a stable API for QT_GalleryModel and its subclasses for populating
224 /// the model from a variety of data sources. Provides a plugin architecture
225 /// for adding new UT_GalleryDataSourceImpl subclasses which are constructed
226 /// based on the source_identifier sent to this object's constructor. Also
227 /// provides a global registry of UT_GalleryDataSource objects, so there is
228 /// always only one data source created for a given source_identifier.
229 ///
231 {
232 public:
233  UT_GalleryDataSource(const UT_StringHolder &source_identifier,
234  const UT_StringHolder &args);
236 
238 
239  typedef UT_Function
241  typedef UT_Function
244  static void registerDataSourceImplementation(
245  const ValidatorFunc &validator,
246  const CreatorFunc &creator);
247 
248  /// Return true if this gallery data source owns a valid data source
249  /// implementation object. You can still call all the methods on an
250  /// invalid object, but they do nothing. This check allows the UI to
251  /// present an error message for an invalid source identifier.
252  bool isValid() const
253  { return myImpl && myImpl->isValid(); }
254  /// Return true if the source implementation is read only.
255  bool isReadOnly() const
256  { return myImpl->isReadOnly(); }
257  /// Return true if the source supports mutable per-item annotations even
258  /// when isReadOnly() is true.
259  bool supportsAnnotations() const
260  { return myImpl->supportsAnnotations(); }
261  /// Return true if this specific item is read-only. Only called
262  /// when isReadOnly() is false.
263  bool isItemReadOnly(const UT_StringRef &item_id) const
264  { return myImpl->isItemReadOnly(item_id); }
265  /// Return the source identifier.
267  { return mySourceIdentifier; }
268  /// Return the source args.
270  { return mySourceArgs; }
271  /// Return HTML formatted info about the data source.
273  { return myImpl->infoHtml(); }
274 
275  /// Begins/ends transactions so that functions which end up
276  /// generating large numbers of queries/modifications can be
277  /// more efficient.
278  void startTransaction() const
279  { myImpl->startTransaction(); }
280  void endTransaction(bool commit = true) const
281  { myImpl->endTransaction(); }
282 
283  /// Populate an array with all valid item ids.
284  void itemIds(UT_StringArray &item_ids) const
285  { item_ids.clear(); myImpl->itemIds(item_ids); }
286  void updatedItemIds(UT_StringArray &item_ids);
287 
288  /// Populate an array with all valid item ids with the given parent 'item_id'
289  void childItemIds(const UT_StringRef &parent_item_id, UT_StringArray &item_ids) const
290  { item_ids.clear(); myImpl->childItemIds(parent_item_id, item_ids); }
291 
292  /// Return the source type.
294  { return myImpl->sourceTypeName(item_id); }
295  UT_StringHolder typeName(const UT_StringRef &item_id) const
296  { return myImpl->typeName(item_id); }
298  { return myImpl->renderMethod(item_id); }
299  UT_StringHolder label(const UT_StringRef &item_id) const
300  { return myImpl->label(item_id); }
301  UT_WorkBuffer thumbnail(const UT_StringRef &item_id) const
302  { return myImpl->thumbnail(item_id); }
303  UT_StringHolder treeIcon(const UT_StringRef &item_id) const
304  { return myImpl->treeIcon(item_id); }
305  time_t creationDate(const UT_StringRef &item_id) const
306  { return myImpl->creationDate(item_id); }
307  time_t modificationDate(const UT_StringRef &item_id) const
308  { return myImpl->modificationDate(item_id); }
309  bool isStarred(const UT_StringRef &item_id) const
310  { return myImpl->isStarred(item_id); }
311  UT_StringHolder colorTag(const UT_StringRef &item_id) const
312  { return myImpl->colorTag(item_id); }
313  UT_StringSet tags(const UT_StringRef &item_id) const
314  { return myImpl->tags(item_id); }
315  UT_Options metadata(const UT_StringRef &item_id) const
316  { return myImpl->metadata(item_id); }
317  UT_StringHolder filePath(const UT_StringRef &item_id) const
318  { return myImpl->filePath(item_id); }
319  bool ownsFile(const UT_StringRef &item_id) const
320  { return myImpl->ownsFile(item_id); }
321  UT_WorkBuffer blindData(const UT_StringRef &item_id) const
322  { return myImpl->blindData(item_id); }
323  UT_StringHolder status(const UT_StringRef &item_id) const
324  { return myImpl->status(item_id); }
325  UT_StringHolder parentId(const UT_StringRef &item_id) const
326  { return myImpl->parentId(item_id); }
328  { return myImpl->prepareItemForUse(item_id); }
329  bool isFilePathEditable(const UT_StringRef &item_id) const
330  { return myImpl->isFilePathEditable(item_id); }
331 
332  bool setRenderMethod(const UT_StringRef &item_id,
333  const UT_StringHolder &render_method);
334  bool setLabel(const UT_StringRef &item_id,
335  const UT_StringHolder &label);
336  bool setThumbnail(const UT_StringRef &item_id,
337  const UT_WorkBuffer &thumbnail);
338  bool setModificationDate(const UT_StringRef &item_id,
339  time_t timestamp);
340  bool setIsStarred(const UT_StringRef &item_id,
341  bool isstarred);
342  bool setColorTag(const UT_StringRef &item_id,
343  const UT_StringHolder &color_tag);
344  bool setMetadata(const UT_StringRef &item_id,
345  const UT_Options &metadata);
346  bool setFilePath(const UT_StringRef &item_id,
347  const char *file_path);
348  bool setOwnsFile(const UT_StringRef &item_id,
349  bool owns_file);
350  bool setBlindData(const UT_StringRef &item_id,
351  const void *data, int data_size);
352  bool setStatus(const UT_StringRef &item_id,
353  const UT_StringHolder &status);
354  bool setParentId(const UT_StringRef &item_id,
355  const UT_StringRef &parent_item_id);
356 
357  bool createTag(const char *tag);
358  bool deleteTag(const char *tag, bool delete_if_assigned);
359  bool addTag(const UT_StringRef &item_id, const char *tag);
360  bool removeTag(const UT_StringRef &item_id, const char *tag);
361 
362  /// Generates a file path to associate with a particular item id, for
363  /// cases where the new item needs a new file, as in a snapshot data source
364  /// (rather than referring to an existing file, as in an asset data source).
365  UT_StringHolder generateItemFilePath(
366  const UT_StringRef &item_id,
367  const char *file_ext);
368 
369  /// Add a new gallery item to the data source.
370  UT_StringHolder addItem(const UT_StringRef &item_type_name,
371  const UT_StringRef &name,
372  const void *thumbnail_data,
373  int thumbnail_data_size,
374  const char *item_file = nullptr,
375  bool item_owns_file = false,
376  const void *item_data = nullptr,
377  int item_data_size = 0,
378  time_t *creation_date = nullptr,
379  const UT_StringRef &parent_id = UT_StringHolder::theEmptyString);
380 
381  /// Mark items for deletion in the data source.
382  /// Do nothing for invalid item ids or items that are already
383  /// marked for deletion.
384  bool markItemsForDeletion(const UT_StringArray &item_ids);
385  /// Unmark items for deletion in the data source.
386  /// Do nothing for invalid item ids or items that are not
387  /// marked for deletion.
388  bool unmarkItemsForDeletion(const UT_StringArray &item_ids);
389 
390  /// For file-based sources, does the equivalent of a "save as" operation.
391  /// The source identifier of the data source should be updated if the
392  /// implementation's save as operation reports success.
393  bool saveAs(const UT_StringHolder &source_identifier);
394 
395 private:
396  UT_StringHolder mySourceIdentifier;
397  UT_StringHolder mySourceArgs;
398  UT_StringHolder myExpandedSourceIdentifier;
400 };
401 
402 #endif
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
#define UT_API
Definition: UT_API.h:14
OutGridT const XformOp bool bool
GLintptr GLsizeiptr GLboolean commit
Definition: glcorearb.h:3363
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
static const UT_StringHolder theEmptyString
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
A map of string to various well defined value types.
Definition: UT_Options.h:87
**If you just want to fire and args
Definition: thread.h:618
void clear()
Resets list to an empty list.
Definition: UT_Array.h:753
Definition: format.h:1821