| 1 | // |
|---|
| 2 | // SapphireVirtualDirectory.h |
|---|
| 3 | // Sapphire |
|---|
| 4 | // |
|---|
| 5 | // Created by Graham Booker on 11/18/07. |
|---|
| 6 | // Copyright 2007 www.nanopi.net. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SapphireMetaData.h" |
|---|
| 10 | |
|---|
| 11 | /*! |
|---|
| 12 | * @brief The base Virtual directory |
|---|
| 13 | * |
|---|
| 14 | * This class is designed to be a virtual directory without any basis in reality. It contains all the shared code for subclasses to store their information. |
|---|
| 15 | */ |
|---|
| 16 | @interface SapphireVirtualDirectory : SapphireDirectoryMetaData { |
|---|
| 17 | NSMutableDictionary *directory; /*!< @brief The directory of files since there isn't a real directory*/ |
|---|
| 18 | NSTimer *reloadTimer; /*!< @brief A timer to reload the visual contents (not retained)*/ |
|---|
| 19 | BOOL loading; /*!< @brief TRUE if the directory is still loading*/ |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | /*! |
|---|
| 23 | * @brief Creates a new virtual directory object |
|---|
| 24 | * |
|---|
| 25 | * This creates a new virtual directory metadata object. It is similar to its superclass, but has no persistent store. |
|---|
| 26 | * |
|---|
| 27 | * @param myParent The parent meta data |
|---|
| 28 | * @param myPath The path for this meta data |
|---|
| 29 | * @return The meta data object |
|---|
| 30 | */ |
|---|
| 31 | - (id)initWithParent:(SapphireVirtualDirectory *)myParent path:(NSString *)myPath; |
|---|
| 32 | |
|---|
| 33 | /*! |
|---|
| 34 | * @brief Sets a timer to reload |
|---|
| 35 | * |
|---|
| 36 | * The timer is set to reload the contents so that updates can be consolidated. |
|---|
| 37 | */ |
|---|
| 38 | - (void)setReloadTimer; |
|---|
| 39 | |
|---|
| 40 | /*! |
|---|
| 41 | * @brief Process a file to add to the virtual directory |
|---|
| 42 | * |
|---|
| 43 | * @param file The file to add |
|---|
| 44 | */ |
|---|
| 45 | - (void)processFile:(SapphireFileMetaData *)file; |
|---|
| 46 | |
|---|
| 47 | /*! |
|---|
| 48 | * @brief Process a file to remove from the virtual directory |
|---|
| 49 | * |
|---|
| 50 | * @param file The file to remove |
|---|
| 51 | */ |
|---|
| 52 | - (void)removeFile:(SapphireFileMetaData *)file; |
|---|
| 53 | |
|---|
| 54 | /*! |
|---|
| 55 | * @brief The default cover art path for directories in this class |
|---|
| 56 | * |
|---|
| 57 | * @return The cover art path for this class |
|---|
| 58 | */ |
|---|
| 59 | - (NSString *)classDefaultCoverPath; |
|---|
| 60 | |
|---|
| 61 | /*! |
|---|
| 62 | * @brief A child of this directory had its contents change |
|---|
| 63 | * |
|---|
| 64 | * This is a trigger for the current object to do an update. Since the child's display has changed, this object may need to change its display to match |
|---|
| 65 | */ |
|---|
| 66 | - (void)childDisplayChanged; |
|---|
| 67 | |
|---|
| 68 | /*! |
|---|
| 69 | * @brief Write directory structure to a file |
|---|
| 70 | * |
|---|
| 71 | * This is for debug purposes. It writes the entire directory structure to a file to test its opperation |
|---|
| 72 | */ |
|---|
| 73 | - (void)writeToFile:(NSString *)filePath; |
|---|
| 74 | |
|---|
| 75 | /*! |
|---|
| 76 | * @brief Determines if the display is empty |
|---|
| 77 | * |
|---|
| 78 | * @return YES if the display is empty, NO if it contians at least one object |
|---|
| 79 | */ |
|---|
| 80 | - (BOOL)isDisplayEmpty; |
|---|
| 81 | |
|---|
| 82 | /*! |
|---|
| 83 | * @brief Determines if the directory is empty |
|---|
| 84 | * |
|---|
| 85 | * @return YES if the directory is empty, NO if it contians at least one object |
|---|
| 86 | */ |
|---|
| 87 | - (BOOL)isEmpty; |
|---|
| 88 | |
|---|
| 89 | /*! |
|---|
| 90 | * @brief Determines if the directory is loaded |
|---|
| 91 | * |
|---|
| 92 | * @return YES if the directory is fully loadded, NO otherwise |
|---|
| 93 | */ |
|---|
| 94 | - (BOOL)isLoaded; |
|---|
| 95 | @end |
|---|
| 96 | |
|---|
| 97 | /*! |
|---|
| 98 | * @brief A virtual directory containing other virtual directories |
|---|
| 99 | * |
|---|
| 100 | * This is a subclass of SapphireVirtualDirectory which contains abstract methods to make its subclasses easier. It provides methods for adding a file to its directory and creating the child object if necessary. |
|---|
| 101 | */ |
|---|
| 102 | @interface SapphireVirtualDirectoryOfDirectories : SapphireVirtualDirectory { |
|---|
| 103 | } |
|---|
| 104 | /*! |
|---|
| 105 | * @brief Add a file to the subdirectories |
|---|
| 106 | * |
|---|
| 107 | * This method exists to make directories of directories easier. If a file is added with a certain key, this method does everything that is needed. |
|---|
| 108 | * |
|---|
| 109 | * For example with TV shows. The SapphireTVDirectory needs to add Dexter 2x12. It calls this method with the file meta data, the key of "Dexter" and a class of SapphireShowDirectory. It will lookup the directory with the key "Dexter" and if nothing exists there yet, it will create a new SapphireShowDirectory and place it in the directory. Then it will call the SapphireShowDirectory object's processFile. If a new directory was created, and it is still empty after that call, it is then removed. Lastly, the reload time is called. |
|---|
| 110 | * |
|---|
| 111 | * @param file The file to add |
|---|
| 112 | * @param key The key of the subdirectory which is to contain the file |
|---|
| 113 | * @param childClass The class of the child directory |
|---|
| 114 | * @return YES if the file was added, NO otherwise |
|---|
| 115 | */ |
|---|
| 116 | - (BOOL)addFile:(SapphireFileMetaData *)file toKey:(NSString *)key withChildClass:(Class)childClass; |
|---|
| 117 | |
|---|
| 118 | /*! |
|---|
| 119 | * @brief Remove a file from the subdirectories |
|---|
| 120 | * |
|---|
| 121 | * This method exists to make directories of directories easier. If a removed from a certain directory, this does all that is needed. It will have the subdirectory remove the file, and then if the subdirectory is empty, remove the subdirectory itself. |
|---|
| 122 | * |
|---|
| 123 | * @param file The file to remove |
|---|
| 124 | * @param key The key of the subdirectory which contains the file |
|---|
| 125 | * @return YES if the subdirectory was removed, NO otherwise |
|---|
| 126 | */ |
|---|
| 127 | - (BOOL)removeFile:(SapphireFileMetaData *)file fromKey:(NSString *)key; |
|---|
| 128 | @end |
|---|