1 /******************************************************************************
2  * Copyright (c) 2005-2019 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 #import "VDKQueue.h"
29 
30 @class AddMagnetWindowController;
31 @class AddWindowController;
32 @class Badger;
33 @class DragOverlayWindow;
34 @class FilterBarController;
35 @class InfoWindowController;
36 @class MessageWindowController;
37 @class PrefsController;
38 @class StatusBarController;
39 @class Torrent;
40 @class TorrentTableView;
41 @class URLSheetWindowController;
42 
43 typedef enum
44 {
45     ADD_MANUAL,
46     ADD_AUTO,
47     ADD_SHOW_OPTIONS,
48     ADD_URL,
49     ADD_CREATED
50 } addType;
51 
52 @interface Controller : NSObject <NSURLDownloadDelegate, NSUserNotificationCenterDelegate, NSPopoverDelegate, NSSharingServiceDelegate, NSSharingServicePickerDelegate, NSSoundDelegate, NSToolbarDelegate, NSWindowDelegate, QLPreviewPanelDataSource, QLPreviewPanelDelegate, VDKQueueDelegate>
53 {
54     tr_session                      * fLib;
55 
56     NSMutableArray                  * fTorrents, * fDisplayedTorrents;
57 
58     PrefsController                 * fPrefsController;
59     InfoWindowController            * fInfoController;
60     MessageWindowController         * fMessageController;
61 
62     NSUserDefaults                  * fDefaults;
63 
64     NSString                        * fConfigDirectory;
65 
66     IBOutlet NSWindow               * fWindow;
67     DragOverlayWindow               * fOverlayWindow;
68     IBOutlet TorrentTableView       * fTableView;
69 
70     io_connect_t                    fRootPort;
71     NSTimer                         * fTimer;
72 
73     VDKQueue                        * fFileWatcherQueue;
74 
75     IBOutlet NSMenuItem             * fOpenIgnoreDownloadFolder;
76     IBOutlet NSButton               * fActionButton, * fSpeedLimitButton, * fClearCompletedButton;
77     IBOutlet NSTextField            * fTotalTorrentsField;
78 
79     StatusBarController             * fStatusBar;
80 
81     FilterBarController             * fFilterBar;
82     IBOutlet NSMenuItem             * fNextFilterItem;
83 
84     IBOutlet NSMenuItem             * fNextInfoTabItem, * fPrevInfoTabItem;
85 
86     IBOutlet NSMenu                 * fSortMenu;
87 
88     IBOutlet NSMenu                 * fGroupsSetMenu, * fGroupsSetContextMenu;
89 
90     IBOutlet NSMenu                 * fShareMenu, * fShareContextMenu;
91     IBOutlet NSMenuItem             * fShareMenuItem, * fShareContextMenuItem; // remove when dropping 10.6
92 
93     QLPreviewPanel                  * fPreviewPanel;
94     BOOL                            fQuitting;
95     BOOL                            fQuitRequested;
96     BOOL                            fPauseOnLaunch;
97 
98     Badger                          * fBadger;
99 
100     NSMutableArray                  * fAutoImportedNames;
101     NSTimer                         * fAutoImportTimer;
102 
103     NSMutableDictionary             * fPendingTorrentDownloads;
104 
105     NSMutableSet                    * fAddingTransfers;
106 
107     NSMutableSet                    * fAddWindows;
108     URLSheetWindowController        * fUrlSheetController;
109 
110     BOOL                            fGlobalPopoverShown;
111     BOOL                            fSoundPlaying;
112 }
113 
114 - (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path;
115 
116 - (void) askOpenConfirmed: (AddWindowController *) addController add: (BOOL) add;
117 - (void) openCreatedFile: (NSNotification *) notification;
118 - (void) openFilesWithDict: (NSDictionary *) dictionary;
119 - (void) openShowSheet: (id) sender;
120 
121 - (void) openMagnet: (NSString *) address;
122 - (void) askOpenMagnetConfirmed: (AddMagnetWindowController *) addController add: (BOOL) add;
123 
124 - (void) invalidOpenAlert: (NSString *) filename;
125 - (void) invalidOpenMagnetAlert: (NSString *) address;
126 - (void) duplicateOpenAlert: (NSString *) name;
127 - (void) duplicateOpenMagnetAlert: (NSString *) address transferName: (NSString *) name;
128 
129 - (void) openURL: (NSString *) urlString;
130 - (void) openURLShowSheet: (id) sender;
131 
132 - (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo;
133 
134 - (tr_session *) sessionHandle;
135 
136 - (void) createFile: (id) sender;
137 
138 - (void) resumeSelectedTorrents:    (id) sender;
139 - (void) resumeAllTorrents:         (id) sender;
140 - (void) resumeTorrents:            (NSArray *) torrents;
141 
142 - (void) resumeSelectedTorrentsNoWait:  (id) sender;
143 - (void) resumeWaitingTorrents:         (id) sender;
144 - (void) resumeTorrentsNoWait:          (NSArray *) torrents;
145 
146 - (void) stopSelectedTorrents:      (id) sender;
147 - (void) stopAllTorrents:           (id) sender;
148 - (void) stopTorrents:              (NSArray *) torrents;
149 
150 - (void) removeTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData;
151 - (void) removeSheetDidEnd: (NSWindow *) sheet returnCode: (NSInteger) returnCode
152                         contextInfo: (void *) contextInfo;
153 - (void) confirmRemoveTorrents: (NSArray *) torrents deleteData: (BOOL) deleteData;
154 - (void) removeNoDelete:                (id) sender;
155 - (void) removeDeleteData:              (id) sender;
156 
157 - (void) clearCompleted: (id) sender;
158 
159 - (void) moveDataFilesSelected: (id) sender;
160 - (void) moveDataFiles: (NSArray *) torrents;
161 
162 - (void) copyTorrentFiles: (id) sender;
163 - (void) copyTorrentFileForTorrents: (NSMutableArray *) torrents;
164 
165 - (void) copyMagnetLinks: (id) sender;
166 
167 - (void) revealFile: (id) sender;
168 
169 - (IBAction) renameSelected: (id) sender;
170 
171 - (void) announceSelectedTorrents: (id) sender;
172 
173 - (void) verifySelectedTorrents: (id) sender;
174 - (void) verifyTorrents: (NSArray *) torrents;
175 
176 - (NSArray *)selectedTorrents;
177 
178 @property (nonatomic, readonly) PrefsController * prefsController;
179 - (void) showPreferenceWindow: (id) sender;
180 
181 - (void) showAboutWindow: (id) sender;
182 
183 - (void) showInfo: (id) sender;
184 - (void) resetInfo;
185 - (void) setInfoTab: (id) sender;
186 
187 @property (nonatomic, readonly) MessageWindowController * messageWindowController;
188 - (void) showMessageWindow: (id) sender;
189 - (void) showStatsWindow: (id) sender;
190 
191 - (void) updateUI;
192 - (void) fullUpdateUI;
193 
194 - (void) setBottomCountText: (BOOL) filtering;
195 
196 - (Torrent *) torrentForHash: (NSString *) hash;
197 
198 - (void) torrentFinishedDownloading: (NSNotification *) notification;
199 - (void) torrentRestartedDownloading: (NSNotification *) notification;
200 - (void) torrentFinishedSeeding: (NSNotification *) notification;
201 
202 - (void) updateTorrentHistory;
203 
204 - (void) applyFilter;
205 
206 - (void) sortTorrents: (BOOL) includeQueueOrder;
207 - (void) sortTorrentsCallUpdates: (BOOL) callUpdates includeQueueOrder: (BOOL) includeQueueOrder;
208 - (void) rearrangeTorrentTableArray: (NSMutableArray *) rearrangeArray forParent: (id) parent withSortDescriptors: (NSArray *) descriptors beganTableUpdate: (BOOL *) beganTableUpdate;
209 - (void) setSort: (id) sender;
210 - (void) setSortByGroup: (id) sender;
211 - (void) setSortReverse: (id) sender;
212 
213 - (void) switchFilter: (id) sender;
214 
215 - (IBAction) showGlobalPopover: (id) sender;
216 
217 - (void) setGroup: (id) sender; //used by delegate-generated menu items
218 
219 - (void) toggleSpeedLimit: (id) sender;
220 - (void) speedLimitChanged: (id) sender;
221 - (void) altSpeedToggledCallbackIsLimited: (NSDictionary *) dict;
222 
223 - (void) changeAutoImport;
224 - (void) checkAutoImportDirectory;
225 
226 - (void) beginCreateFile: (NSNotification *) notification;
227 
228 - (void) sleepCallback: (natural_t) messageType argument: (void *) messageArgument;
229 
230 @property (nonatomic, readonly) VDKQueue * fileWatcherQueue;
231 
232 - (void) torrentTableViewSelectionDidChange: (NSNotification *) notification;
233 
234 - (void) toggleSmallView: (id) sender;
235 - (void) togglePiecesBar: (id) sender;
236 - (void) toggleAvailabilityBar: (id) sender;
237 
238 - (void) toggleStatusBar: (id) sender;
239 - (void) showStatusBar: (BOOL) show animate: (BOOL) animate;
240 - (void) toggleFilterBar: (id) sender;
241 - (void) showFilterBar: (BOOL) show animate: (BOOL) animate;
242 - (void) focusFilterField;
243 
244 - (void) allToolbarClicked: (id) sender;
245 - (void) selectedToolbarClicked: (id) sender;
246 
247 - (void) setWindowSizeToFit;
248 - (NSRect) sizedWindowFrame;
249 - (void) updateForAutoSize;
250 - (void) setWindowMinMaxToCurrent;
251 - (CGFloat) minWindowContentSizeAllowed;
252 
253 - (void) updateForExpandCollape;
254 
255 - (void) showMainWindow: (id) sender;
256 
257 - (void) toggleQuickLook: (id) sender;
258 
259 - (void) linkHomepage: (id) sender;
260 - (void) linkForums: (id) sender;
261 - (void) linkGitHub: (id) sender;
262 - (void) linkDonate: (id) sender;
263 
264 - (void) rpcCallback: (tr_rpc_callback_type) type forTorrentStruct: (struct tr_torrent *) torrentStruct;
265 - (void) rpcAddTorrentStruct: (struct tr_torrent *) torrentStruct;
266 - (void) rpcRemoveTorrent: (Torrent *) torrent deleteData: (BOOL) deleteData;
267 - (void) rpcStartedStoppedTorrent: (Torrent *) torrent;
268 - (void) rpcChangedTorrent: (Torrent *) torrent;
269 - (void) rpcMovedTorrent: (Torrent *) torrent;
270 - (void) rpcUpdateQueue;
271 
272 @end
273