source: trunk/Cocoa/X10Remote/X10RemoteController.m@ 353

Last change on this file since 353 was 157, checked in by Nicholas Riley, 21 years ago

Initial import.

File size: 2.6 KB
RevLine 
[157]1//
2// X10RemoteController.m
3// X10Remote
4//
5// Created by Nicholas Riley on Sat Jan 24 2004.
6// Copyright (c) 2004 Nicholas Riley. All rights reserved.
7//
8
9#import "X10RemoteController.h"
10#import "NJRHotKey.h"
11#import "NJRHotKeyManager.h"
12#import "NJRWindowMagnetism.h"
13
14@implementation X10RemoteController
15
16- (void)_launchRemoteShellTask;
17{
18 NSLog(@"Attempting to connect to stripped");
19 [remoteShellTask release];
20 remoteShellTask = [[NSTask alloc] init];
21 [remoteShellTask setLaunchPath: @"/bin/zsh"];
22 [remoteShellTask setArguments: [NSArray arrayWithObjects: @"-c", @"ssh stripped /bin/sh", nil]];
23 NSPipe *remoteShellPipe = [NSPipe pipe];
24 [remoteShellTask setStandardInput: remoteShellPipe];
25 remoteShellInput = [remoteShellPipe fileHandleForWriting];
26 [remoteShellTask launch];
27 [remoteShellInput writeData: [NSData data]];
28}
29
30- (void)_toggleVisible:(id)sender;
31{
32 NSWindow *window = [self window];
33 if ([window isVisible]) {
34 if ([window isKeyWindow])
35 [NSApp hide: self];
36 [window orderOut: self];
37 } else {
38 [NSApp activateIgnoringOtherApps: YES];
39 [window makeKeyAndOrderFront: self];
40 }
41}
42
43- (void)awakeFromNib;
44{
45 NJRHotKeyManager *hotKeyManager = [NJRHotKeyManager sharedManager];
46 NSWindow *window = [self window];
47 [hotKeyManager addShortcutWithIdentifier: @"X10RemoteControllerToggleVisible"
48 hotKey: [NJRHotKey hotKeyWithCharacters: @"x"
49 modifierFlags: NSCommandKeyMask | NSControlKeyMask
50 keyCode: 7]
51 target: self
52 action: @selector(_toggleVisible:)];
53 [self _launchRemoteShellTask];
54 [window setHidesOnDeactivate: NO];
55 [[NJRWindowMagnetism alloc] initForWindow: window];
56}
57
58- (void)_sendToRemote:(NSString *)commandString;
59{
60 NSData *commandData = [commandString dataUsingEncoding: NSASCIIStringEncoding];
61 if (![remoteShellTask isRunning])
62 [self _launchRemoteShellTask];
63 [remoteShellInput writeData: commandData];
64 if (![remoteShellTask isRunning]) {
65 [self _launchRemoteShellTask];
66 [remoteShellInput writeData: commandData];
67 }
68}
69
70- (IBAction)turnUnitOn:(NSButton *)sender;
71{
72 [self _sendToRemote: [NSString stringWithFormat: @"br n%d on\n", [sender tag]]];
73}
74
75- (IBAction)turnUnitOff:(NSButton *)sender;
76{
77 [self _sendToRemote: [NSString stringWithFormat: @"br n%d off\n", [sender tag]]];
78}
79
80@end
Note: See TracBrowser for help on using the repository browser.