1 /****************************************************************************** 2 * Copyright (c) 2006-2012 Transmission authors and contributors 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 *****************************************************************************/ 22 23 #import <Cocoa/Cocoa.h> 24 #import <Quartz/Quartz.h> 25 26 #include <libtransmission/transmission.h> 27 28 @class FileListNode; 29 30 typedef enum { 31 TorrentDeterminationAutomatic = 0, 32 TorrentDeterminationUserSpecified 33 } TorrentDeterminationType; 34 35 #define kTorrentDidChangeGroupNotification @"TorrentDidChangeGroup" 36 37 @interface Torrent : NSObject <NSCopying, QLPreviewItem> 38 { 39 tr_torrent * fHandle; 40 const tr_info * fInfo; 41 const tr_stat * fStat; 42 43 NSUserDefaults * fDefaults; 44 45 NSImage * fIcon; 46 47 NSString * fHashString; 48 49 tr_file_stat * fFileStat; 50 NSArray * fFileList, * fFlatFileList; 51 52 NSIndexSet * fPreviousFinishedIndexes; 53 NSDate * fPreviousFinishedIndexesDate; 54 55 BOOL fRemoveWhenFinishSeeding; 56 57 NSInteger fGroupValue; 58 TorrentDeterminationType fGroupValueDetermination; 59 60 TorrentDeterminationType fDownloadFolderDetermination; 61 62 BOOL fResumeOnWake; 63 64 BOOL fTimeMachineExcludeInitialized; 65 } 66 67 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete 68 lib: (tr_session *) lib; 69 - (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib; 70 - (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib; 71 - (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause; 72 73 - (NSDictionary *) history; 74 75 - (void) closeRemoveTorrent: (BOOL) trashFiles; 76 77 - (void) changeDownloadFolderBeforeUsing: (NSString *) folder determinationType: (TorrentDeterminationType) determinationType; 78 79 - (NSString *) currentDirectory; 80 81 - (void) getAvailability: (int8_t *) tab size: (NSInteger) size; 82 - (void) getAmountFinished: (float *) tab size: (NSInteger) size; 83 - (NSIndexSet *) previousFinishedPieces; 84 - (void) setPreviousFinishedPieces: (NSIndexSet *) indexes; 85 86 - (void) update; 87 88 - (void) startTransferIgnoringQueue: (BOOL) ignoreQueue; 89 - (void) startTransferNoQueue; 90 - (void) startTransfer; 91 - (void) stopTransfer; 92 - (void) sleep; 93 - (void) wakeUp; 94 95 - (NSInteger) queuePosition; 96 - (void) setQueuePosition: (NSUInteger) index; 97 98 - (void) manualAnnounce; 99 - (BOOL) canManualAnnounce; 100 101 - (void) resetCache; 102 103 - (BOOL) isMagnet; 104 - (NSString *) magnetLink; 105 106 - (CGFloat) ratio; 107 - (tr_ratiolimit) ratioSetting; 108 - (void) setRatioSetting: (tr_ratiolimit) setting; 109 - (CGFloat) ratioLimit; 110 - (void) setRatioLimit: (CGFloat) limit; 111 - (CGFloat) progressStopRatio; 112 113 - (tr_idlelimit) idleSetting; 114 - (void) setIdleSetting: (tr_idlelimit) setting; 115 - (NSUInteger) idleLimitMinutes; 116 - (void) setIdleLimitMinutes: (NSUInteger) limit; 117 118 - (BOOL) usesSpeedLimit: (BOOL) upload; 119 - (void) setUseSpeedLimit: (BOOL) use upload: (BOOL) upload; 120 - (NSInteger) speedLimit: (BOOL) upload; 121 - (void) setSpeedLimit: (NSInteger) limit upload: (BOOL) upload; 122 - (BOOL) usesGlobalSpeedLimit; 123 - (void) setUseGlobalSpeedLimit: (BOOL) use; 124 125 - (void) setMaxPeerConnect: (uint16_t) count; 126 - (uint16_t) maxPeerConnect; 127 128 @property (nonatomic) BOOL removeWhenFinishSeeding; 129 130 - (BOOL) waitingToStart; 131 132 - (tr_priority_t) priority; 133 - (void) setPriority: (tr_priority_t) priority; 134 135 + (BOOL) trashFile: (NSString *) path error: (NSError **) error; 136 - (void) moveTorrentDataFileTo: (NSString *) folder; 137 - (void) copyTorrentFileTo: (NSString *) path; 138 139 - (BOOL) alertForRemainingDiskSpace; 140 141 - (NSImage *) icon; 142 143 - (NSString *) name; 144 - (BOOL) isFolder; 145 - (uint64_t) size; 146 - (uint64_t) sizeLeft; 147 148 - (NSMutableArray *) allTrackerStats; 149 - (NSArray *) allTrackersFlat; //used by GroupRules 150 - (BOOL) addTrackerToNewTier: (NSString *) tracker; 151 - (void) removeTrackers: (NSSet *) trackers; 152 153 - (NSString *) comment; 154 - (NSString *) creator; 155 - (NSDate *) dateCreated; 156 157 - (NSInteger) pieceSize; 158 - (NSInteger) pieceCount; 159 - (NSString *) hashString; 160 - (BOOL) privateTorrent; 161 162 - (NSString *) torrentLocation; 163 - (NSString *) dataLocation; 164 - (NSString *) fileLocation: (FileListNode *) node; 165 166 - (void) renameTorrent: (NSString *) newName completionHandler: (void (^)(BOOL didRename)) completionHandler; 167 - (void) renameFileNode: (FileListNode *) node withName: (NSString *) newName completionHandler: (void (^)(BOOL didRename)) completionHandler; 168 169 - (CGFloat) progress; 170 - (CGFloat) progressDone; 171 - (CGFloat) progressLeft; 172 - (CGFloat) checkingProgress; 173 174 - (CGFloat) availableDesired; 175 176 - (BOOL) isActive; 177 - (BOOL) isSeeding; 178 - (BOOL) isChecking; 179 - (BOOL) isCheckingWaiting; 180 - (BOOL) allDownloaded; 181 - (BOOL) isComplete; 182 - (BOOL) isFinishedSeeding; 183 - (BOOL) isError; 184 - (BOOL) isAnyErrorOrWarning; 185 - (NSString *) errorMessage; 186 187 - (NSArray *) peers; 188 189 - (NSUInteger) webSeedCount; 190 - (NSArray *) webSeeds; 191 192 - (NSString *) progressString; 193 - (NSString *) statusString; 194 - (NSString *) shortStatusString; 195 - (NSString *) remainingTimeString; 196 197 - (NSString *) stateString; 198 - (NSInteger) totalPeersConnected; 199 - (NSInteger) totalPeersTracker; 200 - (NSInteger) totalPeersIncoming; 201 - (NSInteger) totalPeersCache; 202 - (NSInteger) totalPeersPex; 203 - (NSInteger) totalPeersDHT; 204 - (NSInteger) totalPeersLocal; 205 - (NSInteger) totalPeersLTEP; 206 207 - (NSInteger) peersSendingToUs; 208 - (NSInteger) peersGettingFromUs; 209 210 - (CGFloat) downloadRate; 211 - (CGFloat) uploadRate; 212 - (CGFloat) totalRate; 213 - (uint64_t) haveVerified; 214 - (uint64_t) haveTotal; 215 - (uint64_t) totalSizeSelected; 216 - (uint64_t) downloadedTotal; 217 - (uint64_t) uploadedTotal; 218 - (uint64_t) failedHash; 219 220 - (NSInteger) groupValue; 221 - (void) setGroupValue: (NSInteger) groupValue determinationType: (TorrentDeterminationType) determinationType;; 222 - (NSInteger) groupOrderValue; 223 - (void) checkGroupValueForRemoval: (NSNotification *) notification; 224 225 - (NSArray *) fileList; 226 - (NSArray *) flatFileList; 227 - (NSInteger) fileCount; 228 - (void) updateFileStat; 229 230 //methods require fileStats to have been updated recently to be accurate 231 - (CGFloat) fileProgress: (FileListNode *) node; 232 - (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index; 233 - (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet; 234 - (NSInteger) checkForFiles: (NSIndexSet *) indexSet; 235 - (void) setFileCheckState: (NSInteger) state forIndexes: (NSIndexSet *) indexSet; 236 - (void) setFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet; 237 - (BOOL) hasFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet; 238 - (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet; 239 240 - (NSDate *) dateAdded; 241 - (NSDate *) dateCompleted; 242 - (NSDate *) dateActivity; 243 - (NSDate *) dateActivityOrAdd; 244 245 - (NSInteger) secondsDownloading; 246 - (NSInteger) secondsSeeding; 247 248 - (NSInteger) stalledMinutes; 249 - (BOOL) isStalled; 250 251 - (void) updateTimeMachineExclude; 252 253 - (NSInteger) stateSortKey; 254 - (NSString *) trackerSortKey; 255 256 - (tr_torrent *) torrentStruct; 257 258 @end 259