Skip to content

Commit

Permalink
added uninstallation button to the settings window, complete with a c…
Browse files Browse the repository at this point in the history
…onfirmation sheet and success/failure sheets too
  • Loading branch information
Simone Manganelli authored and Simone Manganelli committed Jun 25, 2009
1 parent a193408 commit 7851b47
Show file tree
Hide file tree
Showing 3 changed files with 1,042 additions and 33 deletions.
11 changes: 11 additions & 0 deletions Plugin/CTFWhitelistWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ extern NSString* kCTFCheckForUpdates;
@interface CTFWhitelistWindowController : NSWindowController {
IBOutlet NSArrayController *_controller;
IBOutlet NSButton *_checkNowButton;

IBOutlet NSPanel *confirmUninstallSheet;
IBOutlet NSPanel *successfulUninstallationSheet;
IBOutlet NSPanel *failedUninstallationSheet;
}

- (IBAction)checkForUpdates:(id)sender;
- (IBAction)uninstallClickToFlash:(id)sender;

- (IBAction)cancelUninstall:(id)sender;
- (IBAction)approveUninstall:(id)sender;

- (IBAction)dismissSuccessSheet:(id)sender;
- (IBAction)dismissFailureSheet:(id)sender;

@end

94 changes: 94 additions & 0 deletions Plugin/CTFWhitelistWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,98 @@ - (NSString *)versionString
return [CTFBundle objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}

- (IBAction)uninstallClickToFlash:(id)sender;
{
[NSApp beginSheet:confirmUninstallSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}

- (IBAction)cancelUninstall:(id)sender;
{
[confirmUninstallSheet orderOut:sender];

[NSApp endSheet:confirmUninstallSheet returnCode:0];
}

- (IBAction)approveUninstall:(id)sender;
{
[confirmUninstallSheet orderOut:sender];

[NSApp endSheet:confirmUninstallSheet returnCode:1];
}

- (void)sheetDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
{
if (returnCode == 1) {
NSString *userPluginPath = [@"~/Library/Internet Plug-ins/ClickToFlash.webplugin" stringByExpandingTildeInPath];
BOOL isDirectory = NO;
BOOL userPluginExists = [[NSFileManager defaultManager] fileExistsAtPath:userPluginPath
isDirectory:&isDirectory];
BOOL succeeded = NO;
if (userPluginExists && isDirectory) {
// we'll move the plugin to the trash, instead of just obstinately
// deleting it
succeeded = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation
source:[@"~/Library/Internet Plug-ins/" stringByExpandingTildeInPath]
destination:nil
files:[NSArray arrayWithObject:@"ClickToFlash.webplugin"]
tag:nil];
}

if (succeeded) {
[NSApp beginSheet:successfulUninstallationSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
} else {
// there are three ways to get here:

// 1. either userPluginExists equals NO, in which case the plugin is
// installed for all users and we can't guarantee that we can
// uninstall it, so we'll just fail

// 2. an item exists at the correct path, but it's a file not a
// folder, so it's not ClickToFlash

// 3. the plugin exists, but for some reason we couldn't move
// it to the trash

[NSApp beginSheet:failedUninstallationSheet
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(resultSheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
} else {
// uninstallation was cancelled
}
}

- (IBAction)dismissSuccessSheet:(id)sender;
{
[successfulUninstallationSheet orderOut:sender];

[NSApp endSheet:successfulUninstallationSheet returnCode:0];
}

- (IBAction)dismissFailureSheet:(id)sender;
{
[failedUninstallationSheet orderOut:sender];

[NSApp endSheet:failedUninstallationSheet returnCode:0];
}

- (void)returnSheetDidEnd:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
{
// nothing to see here!
}

@end
Loading

0 comments on commit 7851b47

Please sign in to comment.