3 * Copyright (c) 2008, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import "AppController.h"
19 #import <libssh2_sftp.h>
20 #import <sys/socket.h>
23 @interface AppController (Private
)
26 - (void)setStatus
:(NSString
*)msg isError
:(BOOL)error
;
31 @implementation AppController
34 * Set up the printer list
38 if (self = [super init
])
40 printers
= [NSMutableArray array
];
42 NSArray
*values
= [NSArray arrayWithObjects
:@
"Double-Sided, Stapled $0.05", @
"publp", nil];
43 NSArray
*keys
= [NSArray arrayWithObjects
:@
"displayName", @
"unixName", nil];
44 [printers addObject
:[NSDictionary dictionaryWithObjects
:values forKeys
:keys
]];
46 values
= [NSArray arrayWithObjects
:@
"Single-Sided, Stapled $0.10", @
"pubps", nil];
47 [printers addObject
:[NSDictionary dictionaryWithObjects
:values forKeys
:keys
]];
49 values
= [NSArray arrayWithObjects
:@
"Double-Sided, Not Stapled $0.05", @
"publpns", nil];
50 [printers addObject
:[NSDictionary dictionaryWithObjects
:values forKeys
:keys
]];
52 values
= [NSArray arrayWithObjects
:@
"Single-Sided, Not Stapled $0.10", @
"pubpsns", nil];
53 [printers addObject
:[NSDictionary dictionaryWithObjects
:values forKeys
:keys
]];
59 * Sets the status text
61 - (void)setStatus
:(NSString
*)msg isError
:(BOOL)error
63 [status setStringValue
:msg
];
66 [status setTextColor
:[NSColor redColor
]];
67 [progress stopAnimation
:self];
71 [status setTextColor
:[NSColor blackColor
]];
76 * Sends an item to the printer
78 - (IBAction
)print
:(id)sender
80 [progress startAnimation
:self];
81 [progress setHidden
:NO
];
82 [status setHidden
:NO
];
84 NSString
*printer
= [[printersController selection
] valueForKey
:@
"unixName"];
86 NSLog(@
"printer = %@", printer
);
87 LIBSSH2_SESSION
*ssh
= libssh2_session_init();
90 return [self setStatus
:@
"Failed to initialize SSH context" isError
:YES
];
93 struct sockaddr_in sin
;
94 int sock
= socket(AF_INET
, SOCK_STREAM
, 0);
95 sin.sin_port
= htons(22);
96 in_addr_t t
= inet_addr("acs.bu.edu");
97 sin.sin_addr.s_addr
= inet_addr("acs.bu.edu");
98 sin.sin_family
= AF_INET
;
99 if (connect(sock
, (struct sockaddr
*)(&sin
), sizeof(struct sockaddr_in
)) != 0)
101 return [self setStatus
:@
"Could not connect to acs.bu.edu" isError
:YES
];