Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSAlert #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion WiredAppKit/NSAlert-WIAppKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ void OABeginAlertSheet(NSString *title, NSString *defaultButton, NSString *alter
if (otherButton)
[alert addButtonWithTitle:otherButton];

[alert beginSheetModalForWindow:docWindow completionHandler:completionHandler];
//[alert beginSheetModalForWindow:docWindow completionHandler:completionHandler];
[alert release]; // retained by the runner while the sheet is up
}
24 changes: 24 additions & 0 deletions WiredAppKit/WIConfigManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// WIConfigManager.h
// WiredFrameworks
//
// Created by Rafaël Warnault on 23/06/13.
// Copyright (c) 2013 Read-Write. All rights reserved.
//

#import <WiredFoundation/WiredFoundation.h>

@class WIError;

@interface WIConfigManager : WIObject {
NSString *_configPath;

WIDateFormatter *_dateFormatter;
}

- (id)initWithConfigPath:(NSString *)configPath;

- (BOOL)setString:(NSString *)string forConfigWithName:(NSString *)name andWriteWithError:(WIError **)error;
- (NSString *)stringForConfigWithName:(NSString *)name;

@end
131 changes: 131 additions & 0 deletions WiredAppKit/WIConfigManager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// WIConfigManager.m
// WiredFrameworks
//
// Created by Rafaël Warnault on 23/06/13.
// Copyright (c) 2013 Read-Write. All rights reserved.
//

#import "WIConfigManager.h"
#import "WIError.h"

@interface WIConfigManager(Private)

- (NSMutableDictionary *)_readConfig;
- (BOOL)_writeConfig:(NSDictionary *)config error:(WIError **)error;

@end


@implementation WIConfigManager(Private)

- (NSMutableDictionary *)_readConfig {
NSMutableDictionary *config;
NSEnumerator *enumerator;
NSArray *pair;
NSString *file, *line, *name, *value;

config = [NSMutableDictionary dictionary];
file = [NSString stringWithContentsOfFile:_configPath encoding:NSUTF8StringEncoding error:NULL];
enumerator = [[file componentsSeparatedByString:@"\n"] objectEnumerator];

while((line = [enumerator nextObject])) {
if([line hasPrefix:@"#"])
continue;

pair = [line componentsSeparatedByString:@"="];

if([pair count] == 2) {
name = [[pair objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];;
value = [[pair objectAtIndex:1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];;

if([config objectForKey:name])
[[config objectForKey:name] addObject:value];
else
[config setObject:[NSMutableArray arrayWithObject:value] forKey:name];
}
}

return config;
}



- (BOOL)_writeConfig:(NSDictionary *)config error:(WIError **)error {
NSEnumerator *enumerator, *valueEnumerator;
NSMutableString *string;
NSString *key, *value;

string = [NSMutableString string];

[string appendString: [NSSWF:@"# This file was generated by %@ at %@\n",
[[self bundle] objectForInfoDictionaryKey:@"CFBundleExecutable"],
[_dateFormatter stringFromDate:[NSDate date]]]];

enumerator = [[[config allKeys] sortedArrayUsingSelector:@selector(compare:)] objectEnumerator];

while((key = [enumerator nextObject])) {
valueEnumerator = [[config objectForKey:key] objectEnumerator];

while((value = [valueEnumerator nextObject]))
[string appendFormat:@"%@ = %@\n", key, value];
}

return [[string dataUsingEncoding:NSUTF8StringEncoding] writeToFile:_configPath options:NSAtomicWrite error:(NSError **) &error];
}

@end



@implementation WIConfigManager

- (id)initWithConfigPath:(NSString *)configPath {
self = [super init];

_configPath = [configPath retain];

_dateFormatter = [[WIDateFormatter alloc] init];
[_dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[_dateFormatter setDateStyle:NSDateFormatterShortStyle];

return self;
}



- (void)dealloc {
[_configPath release];
[_dateFormatter release];

[super dealloc];
}



#pragma mark -

- (BOOL)setString:(NSString *)string forConfigWithName:(NSString *)name andWriteWithError:(WIError **)error {
NSMutableDictionary *config;

config = [self _readConfig];

[config setObject:[NSArray arrayWithObject:string] forKey:name];

return [self _writeConfig:config error:error];
}



- (NSString *)stringForConfigWithName:(NSString *)name {
NSDictionary *config;

config = [self _readConfig];

if([[config objectForKey:name] count] == 0)
return NULL;

return [[config objectForKey:name] objectAtIndex:0];
}

@end
1 change: 1 addition & 0 deletions WiredAppKit/WIStatusMenuManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
+ (BOOL) willStartAtLogin:(NSURL *)itemURL;
+ (void) setStartAtLogin:(NSURL *)itemURL enabled:(BOOL)enabled;

+ (BOOL)isHelperRunning:(NSURL *)url;
+ (void)startHelper:(NSURL *)itemURL;
+ (void)stopHelper:(NSURL *)itemURL;

Expand Down
24 changes: 24 additions & 0 deletions WiredAppKit/WIStatusMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ + (void)stopHelper:(NSURL *)itemURL {
system("killall 'Wired Server Helper'");
}

+ (BOOL)isHelperRunning:(NSURL *)url
{
NSBundle *bundle;
NSTask *task;
NSString *executablePath;
BOOL result;

bundle = [NSBundle bundleWithURL:url];
task = [[NSTask alloc] init];
executablePath = [bundle executablePath];
result = NO;

[task setLaunchPath:executablePath];

if([task isRunning]) {
result = YES;
}

[task release];

return result;
}


+ (BOOL) willStartAtLogin:(NSURL *)itemURL
{
Boolean foundIt=false;
Expand Down
1 change: 1 addition & 0 deletions WiredAppKit/WiredAppKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#import <WiredAppKit/WIChatLogController.h>
#import <WiredAppKit/WIChatHistoryBundle.h>
#import <WiredAppKit/WIColorCell.h>
#import <WiredAppKit/WIConfigManager.h>
#import <WiredAppKit/WICrashReportsController.h>
#import <WiredAppKit/WIExceptionHandler.h>
#import <WiredAppKit/WIGraphView.h>
Expand Down
Loading