mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
Added check for update
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
io_connect_t fRootPort;
|
||||
NSArray * fFilenames;
|
||||
NSTimer * fTimer;
|
||||
NSTimer * fUpdateTimer;
|
||||
|
||||
IBOutlet NSPanel * fPrefsWindow;
|
||||
IBOutlet PrefsController * fPrefsController;
|
||||
@@ -76,6 +77,7 @@
|
||||
|
||||
BOOL fHasGrowl;
|
||||
Badger * fBadger;
|
||||
BOOL fCheckIsAutomatic;
|
||||
}
|
||||
|
||||
- (void) advancedChanged: (id) sender;
|
||||
@@ -128,6 +130,10 @@
|
||||
- (void) finderTrash: (NSString *) path;
|
||||
- (void) growlRegister: (id) sender;
|
||||
|
||||
- (void) checkForUpdate: (id) sender;
|
||||
- (void) checkForUpdateTimer: (NSTimer *) timer;
|
||||
- (void) checkForUpdateAuto: (BOOL) automatic;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,8 +36,9 @@
|
||||
#define TOOLBAR_PAUSE_ALL @"Toolbar Pause All"
|
||||
#define TOOLBAR_RESUME_ALL @"Toolbar Resume All"
|
||||
|
||||
#define WEBSITE_URL @"http://transmission.m0k.org/"
|
||||
#define FORUM_URL @"http://transmission.m0k.org/forum/"
|
||||
#define WEBSITE_URL @"http://transmission.m0k.org/"
|
||||
#define FORUM_URL @"http://transmission.m0k.org/forum/"
|
||||
#define VERSION_PLIST_URL @"http://transmission.m0k.org/version.plist"
|
||||
|
||||
#define GROWL_PATH @"/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app"
|
||||
|
||||
@@ -142,12 +143,18 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||
fDownloading = 0;
|
||||
fSeeding = 0;
|
||||
fCompleted = 0;
|
||||
|
||||
fStat = nil;
|
||||
fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self
|
||||
selector: @selector( updateUI: ) userInfo: NULL repeats: YES];
|
||||
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
||||
forMode: NSModalPanelRunLoopMode];
|
||||
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
||||
forMode: NSEventTrackingRunLoopMode];
|
||||
|
||||
[self checkForUpdateTimer: nil];
|
||||
fUpdateTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0
|
||||
target: self selector: @selector( checkForUpdateTimer: )
|
||||
userInfo: NULL repeats: YES];
|
||||
}
|
||||
|
||||
- (void) windowDidBecomeKey: (NSNotification *) n
|
||||
@@ -214,6 +221,7 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||
|
||||
// Stop updating the interface
|
||||
[fTimer invalidate];
|
||||
[fUpdateTimer invalidate];
|
||||
|
||||
// Save history and stop running torrents
|
||||
for( i = 0; i < fCount; i++ )
|
||||
@@ -1092,4 +1100,131 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||
[appleScript release];
|
||||
}
|
||||
|
||||
- (void) checkForUpdate: (id) sender
|
||||
{
|
||||
[self checkForUpdateAuto: NO];
|
||||
}
|
||||
|
||||
- (void) checkForUpdateTimer: (NSTimer *) timer
|
||||
{
|
||||
NSString * check = [fDefaults stringForKey: @"VersionCheck"];
|
||||
if( [check isEqualToString: @"Never"] )
|
||||
return;
|
||||
|
||||
NSTimeInterval interval;
|
||||
if( [check isEqualToString: @"Daily"] )
|
||||
interval = 24 * 3600;
|
||||
else if( [check isEqualToString: @"Weekly"] )
|
||||
interval = 7 * 24 * 3600;
|
||||
else
|
||||
return;
|
||||
|
||||
id lastObject = [fDefaults objectForKey: @"VersionCheckLast"];
|
||||
NSDate * lastDate = [lastObject isKindOfClass: [NSDate class]] ?
|
||||
lastObject : nil;
|
||||
if( lastDate )
|
||||
{
|
||||
NSTimeInterval actualInterval =
|
||||
[[NSDate date] timeIntervalSinceDate: lastDate];
|
||||
if( actualInterval > 0 && actualInterval < interval )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[self checkForUpdateAuto: YES];
|
||||
[fDefaults setObject: [NSDate date] forKey: @"VersionCheckLast"];
|
||||
}
|
||||
|
||||
- (void) checkForUpdateAuto: (BOOL) automatic
|
||||
{
|
||||
fCheckIsAutomatic = automatic;
|
||||
[[NSURL URLWithString: VERSION_PLIST_URL]
|
||||
loadResourceDataNotifyingClient: self usingCache: NO];
|
||||
}
|
||||
|
||||
- (void) URLResourceDidFinishLoading: (NSURL *) sender
|
||||
{
|
||||
NSDictionary * dict = [NSPropertyListSerialization
|
||||
propertyListFromData: [sender resourceDataUsingCache: NO]
|
||||
mutabilityOption: NSPropertyListImmutable
|
||||
format: nil errorDescription: nil];
|
||||
|
||||
//check if plist was actually found and contains a version
|
||||
NSString * webVersion = nil;
|
||||
if (dict)
|
||||
webVersion = [dict objectForKey: @"Version"];
|
||||
if (!webVersion)
|
||||
{
|
||||
if (!fCheckIsAutomatic)
|
||||
{
|
||||
NSAlert * dialog = [[NSAlert alloc] init];
|
||||
[dialog addButtonWithTitle: @"OK"];
|
||||
[dialog setMessageText: @"Error checking for updates."];
|
||||
[dialog setInformativeText:
|
||||
@"Transmission was not able to check the latest version available."];
|
||||
[dialog setAlertStyle: NSInformationalAlertStyle];
|
||||
|
||||
[dialog runModal];
|
||||
[dialog release];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary]
|
||||
objectForKey: (NSString *)kCFBundleVersionKey];
|
||||
|
||||
NSEnumerator * webEnum = [[webVersion componentsSeparatedByString: @"."] objectEnumerator],
|
||||
* currentEnum = [[currentVersion componentsSeparatedByString: @"."] objectEnumerator];
|
||||
NSString * webSub, * currentSub;
|
||||
|
||||
BOOL webGreater = NO;
|
||||
NSComparisonResult result;
|
||||
while ((webSub = [webEnum nextObject]))
|
||||
{
|
||||
if (!(currentSub = [currentEnum nextObject]))
|
||||
{
|
||||
webGreater = YES;
|
||||
break;
|
||||
}
|
||||
|
||||
result = [currentSub compare: webSub options: NSNumericSearch];
|
||||
if (result != NSOrderedSame)
|
||||
{
|
||||
if (result == NSOrderedAscending)
|
||||
webGreater = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (webGreater)
|
||||
{
|
||||
NSAlert * dialog = [[NSAlert alloc] init];
|
||||
[dialog addButtonWithTitle: @"Go to Website"];
|
||||
[dialog addButtonWithTitle:@"Cancel"];
|
||||
[dialog setMessageText: @"New version is available!"];
|
||||
[dialog setInformativeText: [NSString stringWithFormat:
|
||||
@"A newer version (%@) is available for download from the Transmission website.", webVersion]];
|
||||
[dialog setAlertStyle: NSInformationalAlertStyle];
|
||||
|
||||
if ([dialog runModal] == NSAlertFirstButtonReturn)
|
||||
[self linkHomepage: nil];
|
||||
|
||||
[dialog release];
|
||||
}
|
||||
else if (!fCheckIsAutomatic)
|
||||
{
|
||||
NSAlert * dialog = [[NSAlert alloc] init];
|
||||
[dialog addButtonWithTitle: @"OK"];
|
||||
[dialog setMessageText: @"No new versions are available."];
|
||||
[dialog setInformativeText: [NSString stringWithFormat:
|
||||
@"You are running the most current version of Transmission (%@).", currentVersion]];
|
||||
[dialog setAlertStyle: NSInformationalAlertStyle];
|
||||
|
||||
[dialog runModal];
|
||||
[dialog release];
|
||||
}
|
||||
else;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<integer>20</integer>
|
||||
<key>UseAdvancedBar</key>
|
||||
<false/>
|
||||
<key>VersionStartupCheck</key>
|
||||
<true/>
|
||||
<key>VersionCheck</key>
|
||||
<string>Weekly</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
3
macosx/English.lproj/MainMenu.nib/classes.nib
generated
3
macosx/English.lproj/MainMenu.nib/classes.nib
generated
@@ -3,6 +3,7 @@
|
||||
{
|
||||
ACTIONS = {
|
||||
advancedChanged = id;
|
||||
checkForUpdate = id;
|
||||
growlRegister = id;
|
||||
linkForums = id;
|
||||
linkHomepage = id;
|
||||
@@ -65,6 +66,7 @@
|
||||
setPort = id;
|
||||
setQuitMessage = id;
|
||||
setRemoveMessage = id;
|
||||
setUpdate = id;
|
||||
setUploadLimit = id;
|
||||
};
|
||||
CLASS = PrefsController;
|
||||
@@ -81,6 +83,7 @@
|
||||
fPrefsWindow = NSPanel;
|
||||
fQuitCheck = NSButton;
|
||||
fRemoveCheck = NSButton;
|
||||
fUpdatePopUp = NSPopUpButton;
|
||||
fUploadCheck = NSButton;
|
||||
fUploadField = NSTextField;
|
||||
fWindow = NSWindow;
|
||||
|
||||
8
macosx/English.lproj/MainMenu.nib/info.nib
generated
8
macosx/English.lproj/MainMenu.nib/info.nib
generated
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>62 66 426 365 0 0 1280 832 </string>
|
||||
<string>62 69 426 365 0 0 1280 832 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>29</key>
|
||||
@@ -15,7 +15,7 @@
|
||||
<key>589</key>
|
||||
<string>54 521 112 118 0 0 1152 842 </string>
|
||||
<key>783</key>
|
||||
<string>386 439 470 231 0 0 1280 832 </string>
|
||||
<string>387 422 470 265 0 0 1280 832 </string>
|
||||
<key>796</key>
|
||||
<string>412 490 470 129 0 0 1280 832 </string>
|
||||
<key>825</key>
|
||||
@@ -25,6 +25,10 @@
|
||||
<string>443.0</string>
|
||||
<key>IBOldestOS</key>
|
||||
<integer>3</integer>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>783</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>8G32</string>
|
||||
</dict>
|
||||
|
||||
BIN
macosx/English.lproj/MainMenu.nib/keyedobjects.nib
generated
BIN
macosx/English.lproj/MainMenu.nib/keyedobjects.nib
generated
Binary file not shown.
@@ -40,6 +40,7 @@
|
||||
IBOutlet NSButton * fBadgeCompletedCheck;
|
||||
IBOutlet NSButton * fBadgeDownloadRateCheck;
|
||||
IBOutlet NSButton * fBadgeUploadRateCheck;
|
||||
IBOutlet NSPopUpButton * fUpdatePopUp;
|
||||
|
||||
IBOutlet NSTextField * fPortField;
|
||||
IBOutlet NSButton * fUploadCheck;
|
||||
@@ -56,6 +57,7 @@
|
||||
- (void) setQuitMessage: (id) sender;
|
||||
- (void) setRemoveMessage: (id) sender;
|
||||
- (void) setBadge: (id) sender;
|
||||
- (void) setUpdate: (id) sender;
|
||||
- (void) setDownloadLocation: (id) sender;
|
||||
- (void) folderSheetShow: (id) sender;
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
#define DOWNLOAD_TORRENT 2
|
||||
#define DOWNLOAD_ASK 3
|
||||
|
||||
#define UPDATE_DAILY 0
|
||||
#define UPDATE_WEEKLY 1
|
||||
#define UPDATE_NEVER 2
|
||||
|
||||
#define TOOLBAR_GENERAL @"General"
|
||||
#define TOOLBAR_NETWORK @"Network"
|
||||
|
||||
@@ -128,6 +132,20 @@
|
||||
[fBadgeCompletedCheck setState: [fDefaults boolForKey: @"BadgeCompleted"]];
|
||||
[fBadgeDownloadRateCheck setState: [fDefaults boolForKey: @"BadgeDownloadRate"]];
|
||||
[fBadgeUploadRateCheck setState: [fDefaults boolForKey: @"BadgeUploadRate"]];
|
||||
|
||||
/* Check for update */
|
||||
NSString * versionCheck = [fDefaults stringForKey: @"VersionCheck"];
|
||||
if( [versionCheck isEqualToString: @"Daily"] )
|
||||
[fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
|
||||
else if( [versionCheck isEqualToString: @"Weekly"] )
|
||||
[fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
|
||||
else if( [versionCheck isEqualToString: @"Never"] )
|
||||
[fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
|
||||
else
|
||||
{
|
||||
[fDefaults setObject: @"Weekly" forKey: @"VersionCheck"];
|
||||
[fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier:
|
||||
@@ -256,6 +274,22 @@
|
||||
else;
|
||||
}
|
||||
|
||||
- (void) setUpdate: (id) sender
|
||||
{
|
||||
switch( [fUpdatePopUp indexOfSelectedItem] )
|
||||
{
|
||||
case UPDATE_DAILY:
|
||||
[fDefaults setObject: @"Daily" forKey: @"VersionCheck"];
|
||||
break;
|
||||
case UPDATE_WEEKLY:
|
||||
[fDefaults setObject: @"Weekly" forKey: @"VersionCheck"];
|
||||
break;
|
||||
case UPDATE_NEVER:
|
||||
[fDefaults setObject: @"Never" forKey: @"VersionCheck"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setDownloadLocation: (id) sender
|
||||
{
|
||||
//Download folder
|
||||
|
||||
Reference in New Issue
Block a user