#import "AppController.h"
#import "PrnInstall.h"
#import "PrnInstall104.h"
@implementation AppController
//sets points of prninstall and prninstall104 to point to PrnInstall.m and PrnInstall104.m for method calls
PrnInstall * prninstall;
PrnInstall104 * prninstall104;
int i;
int tmp;
int tmp1;
NSString *stTmp;
NSButton *button; //ppc
NSButton *button1; //ppc
-(id) init
{
if ([super init]) {
//initializes the arrays and the points to call other methods
arrPRN = [[NSMutableArray alloc] init];
arrPRNint = [[NSMutableArray alloc] init];
arrSelections = [[NSMutableArray alloc] init];
arrInstalled = [[NSMutableArray alloc] init];
prninstall = [[PrnInstall alloc] init];
prninstall104 = [[PrnInstall104 alloc] init];
arrSelections1 = [[NSArray alloc] init];
}
return self;
}
-(void) dealloc
{
//releases the arrays from memory
[super dealloc];
[arrPRN release];
[arrPRNint release];
[arrSelections release];
[arrSelections1 release];
[super dealloc];
}
- (void)awakeFromNib {
//calls the method to check the verison of OS and sets the value to the approiate value
[self CheckInstalled];
//if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4) { //For Intel Build
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_3) { //for PPC Build
stDvrChk = @"Panther"; //for PPC Build
// stDvrChk = @"Tiger"; //For Intel Build
} else {
// stDvrChk = @"Leopard"; //For Intel Build
stDvrChk = @"Tiger"; //for PPC Build
}
arrSelections1 = [NSArray arrayWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
NSLog(@"%d items in the array\n", [arrSelections1 count]);
if(cse211djq == nil) {
NSLog(@"Nothing in CSE-211-DJQ\n");
} else {
NSLog(@"Something there");
}
for(i=0;i<[arrSelections1 count]; i++) { //PPC Build
button1=[arrSelections1 objectAtIndex:i];
NSLog(@"object at %d is %d \n", i, button1);
}
}
- (IBAction)NextButton:(id)sender
{
// Color Printer
//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
if([arc118clq state]==NSOnState) {
[arrPRN addObject:@"ARC-118-CLQ"];
[arrPRNint addObject:@"ARC118ClQ"];
[arrSelections addObject:arc118clq];
}
if([cse211clq state]==NSOnState) {
[arrPRN addObject:@"CSE-211-CLQ"];
[arrPRNint addObject:@"CSE211CLQ"];
[arrSelections addObject:cse211clq];
}
if([hubatlabclq state]==NSOnState) {
[arrPRN addObject:@"HUB-ATLAB-CLQ"];
[arrPRNint addObject:@"HUBATLABCLQ"];
[arrSelections addObject:hubatlabclq];
}
// Black and Whites
//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
if([arcatlabbwq state]==NSOnState) {
[arrPRN addObject:@"ARC-ATLAB-BWQ"];
[arrPRNint addObject:@"ARCATLABBWQ"];
[arrSelections addObject:arcatlabbwq];
}
if([hscmdlbwq state]==NSOnState) {
[arrPRN addObject:@"HSC-MDL-BWQ"];
[arrPRNint addObject:@"HSCMDLBWQ"];
[arrSelections addObject:hscmdlbwq];
}
if([hubatlabbwq state]==NSOnState) {
[arrPRN addObject:@"HUB-ATLAB-BWQ"];
[arrPRNint addObject:@"HUBATLABBWQ"];
[arrSelections addObject:hubatlabbwq];
}
if([lawpclabbwq state]==NSOnState) {
[arrPRN addObject:@"LAW-PCLAB-BWQ"];
[arrPRNint addObject:@"LAWPCLABBWQ"];
[arrSelections addObject:lawpclabbwq];
}
if([lbw3radbwq state]==NSOnState) {
[arrPRN addObject:@"LBW-3RAD-BWQ"];
[arrPRNint addObject:@"LBW3RADBWQ"];
[arrSelections addObject:lbw3radbwq];
}
if([weiatlabbwq state]==NSOnState) {
[arrPRN addObject:@"WEI-ATLAB-BWQ"];
[arrPRNint addObject:@"WEIATLABBWQ"];
[arrSelections addObject:weiatlabbwq];
}
// Plotters
//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
if([arc118djq state]==NSOnState) {
[arrPRN addObject:@"ARC-118-DJQ"];
[arrPRNint addObject:@"ARC118DJQ"];
[arrSelections addObject:arc118djq];
}
if([cse211djq state]==NSOnState) {
[arrPRN addObject:@"CSE-211-DJQ"];
[arrPRNint addObject:@"CSE211DJQ"];
[arrSelections addObject:cse211djq];
}
if([wei408djq state]==NSOnState) {
[arrPRN addObject:@"WEI-408-DJQ"];
[arrPRNint addObject:@"WEI408DJQ"];
[arrSelections addObject:wei408djq];
}
//prints out array of the selected printers to the NSTextView on the overview page then show the overview page and hides the selection screen
tmp = [arrPRN count];
stTmp = [NSString stringWithFormat:@" \n \nYou have Selected %d out of 19 Printers to Install\n", tmp];
for(i=0; i<[arrPRN count]; i++) {
[textView insertText:[((NSString *) [arrPRN objectAtIndex: i]) stringByAppendingString:@"\n"]];
}
[textView insertText:stTmp];
[textView setEditable:false];
[prnSelector orderOut:nil];
[prnOverview makeKeyAndOrderFront:nil];
}
- (IBAction)BackButton:(id)sender
{
//clears out all the arrays and clears the check boxes so the use may start over again, then hides the overview screen and open the selection screen again
//for(NSButton *button in arrSelections) [button setState:NSOffState]; //Intel Build
/* */ for(i=0;i<[arrSelections count]; i++) { //PPC Build
button=[arrSelections objectAtIndex:i];
[button setState:NSOffState];
}
for(i=0; i<[arrPRN count]; i++) {
[textView setString:@""];
[arrPRN removeAllObjects];
[arrPRNint removeAllObjects];
[arrSelections removeAllObjects];
}
[textView setEditable:true];
[prnOverview orderOut:nil];
[prnSelector makeKeyAndOrderFront:self];
}
- (IBAction)ProcessButton:(id)sender
{
// calls the install file according to the correct OS version, hides the overview screen and shows a progress bar to show the progress
[prnOverview orderOut:nil];
[prnProcessing makeKeyAndOrderFront:self];
[prnProgress setIndeterminate:NO];
for(i=0; i<[arrPRNint count]; i++) {
//sets the length of the progress in time according to the count of arrPRNint array and updates the display until finished
[prnProgress setDoubleValue:100*i/(double)[arrPRNint count]];
[prnProgress displayIfNeeded];
stTmp = [arrPRNint objectAtIndex: i];
/* */if([stDvrChk isEqualToString:@"Panther"]) {
NSRunAlertPanel(@"Installation Error", @"This Installation is made specifically for OS X version of Tiger and Above", @"Ok", nil, nil);
exit(0);
}
if([stDvrChk isEqualToString:@"Tiger"]) {
[arrInstalled addObject:objc_msgSend(prninstall104, NSSelectorFromString(stTmp))];
}
else {
[arrInstalled addObject:objc_msgSend(prninstall, NSSelectorFromString(stTmp))];
}
}
//hides the progress bar and brings up the wrapup screen. Will display the printers that were installed correctly and then display a message panel if there was an error in copying a driver.
[prnProcessing orderOut:nil];
[prnWrapup makeKeyAndOrderFront:self];
NSBeep();
for(i=0; i<[arrInstalled count]; i++) {
[endtextView insertText:[((NSString *) [arrInstalled objectAtIndex: i]) stringByAppendingString:@"\n"]];
}
//checks for errors in the installs and will display the error code to contact the help desk
tmp1 = [arrInstalled count];
stTmp = [NSString stringWithFormat:@" \n \n%d out of %d Printers have been Installed correctly\n", tmp, tmp1];
[endtextView insertText:stTmp];
[endtextView setEditable:false];
if (tmp != tmp1) {
NSRunAlertPanel(@"Driver Error", @"There was some error with insatalling the drivers. Please contact the Help Desk for more information", @"Ok", nil, nil);
}
}
- (IBAction)CancelProcess:(id)sender
{
//clears out all the arrays and clears the check boxes so the use may start over again, then hides the progress screen and open the selection screen again
// for(NSButton *button in arrSelections) [button setState:NSOffState]; //Intel Build
/**/ for(i=0;i<[arrSelections count]; i++) { //PPC Build
button=[arrSelections objectAtIndex:i];
[button setState:NSOffState];
}
for(i=0; i<[arrPRN count]; i++) {
[textView setString:@""];
[arrPRN removeAllObjects];
[arrPRNint removeAllObjects];
[arrSelections removeAllObjects];
}
[prnProcessing orderOut:nil];
[prnSelector makeKeyAndOrderFront:self];
}
- (IBAction)CancelButton:(id)sender
{
exit(0);
}
- (IBAction)HelpButton:(id)sender
{
[prnHelp makeKeyAndOrderFront:self];
}
- (IBAction)AboutButton:(id)sender
{
[prnAbout makeKeyAndOrderFront:self];
}
- (IBAction)OKButton:(id)sender
{
exit(0);
}
- (IBAction)selectall:(id)sender
{
//uses the Selections1 array to select check all the checkboxes
// for(NSButton *button1 in arrSelections1) [button1 setState:NSOnState]; //Intel Build
/* */
for(i=0;i<[arrSelections1 count]; i++) { //PPC Build
button1=[arrSelections1 objectAtIndex:i];
[button1 setState:NSOffState];
}
[selectall setState:NSOffState];
}
- (IBAction)unselectall:(id)sender
{
//uses the Selections1 array to unselect check all the checkboxes after seeing if they are checked
// for(NSButton *button1 in arrSelections1) { //Intel Build
for(i=0;i<[arrSelections1 count]; i++) { //PPC Build
button1=[arrSelections1 objectAtIndex:i]; //PPC Build
if ([button1 state]==NSOnState) {
[button1 setState:NSOffState];
}
[unselectall setState:NSOffState];
}
}
- (void)CheckInstalled {
FILE *myFD = NULL;
char buffer[9];
// Plotters
//will create a file instance to place the value of the system call
myFD = popen("lpstat -a CSE-211-DJQ | grep -o \"accepting\"","r");
//retrieves the output of the system call and places it in the variable of buffer
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[cse211djq setToolTip:@"Printer already Installed"];
[cse211djq setEnabled:false];
} else {
[cse211djq setToolTip:@"CSE Plotters"];
}
//clears the buffer character variable and then closes the instance
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a ARC-118-DJQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[arc118djq setToolTip:@"Printer already Installed"];
[arc118djq setEnabled:false];
} else {
[arc118djq setToolTip:@"Architecture Plotters"];
}
strcpy(buffer, " ");
pclose(myFD);
// Color Printer
myFD = popen("lpstat -a CSE-211-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
if (strncmp (buffer,"accepting", 9) == 0) {
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
[cse211clq setToolTip:@"Printer already Installed"];
[cse211clq setEnabled:false];
} else {
[cse211clq setToolTip:@"CSE Color Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a ARC-118-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[arc118clq setToolTip:@"Printer already Installed"];
[arc118clq setEnabled:false];
} else {
[arc118clq setToolTip:@"Architecture Color Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a HUB-ATLAB-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[hubatlabclq setToolTip:@"Printer already Installed"];
[hubatlabclq setEnabled:false];
} else {
[hubatlabclq setToolTip:@"Hub Color Printers (Rooms 120 and 224)"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a NRN-G514-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[nrng514clq setToolTip:@"Printer already Installed"];
[nrng514clq setEnabled:false];
} else {
[nrng514clq setToolTip:@"Norman Hall Color Printers"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a WEI-408-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[wei408clq setToolTip:@"Printer already Installed"];
[wei408clq setEnabled:false];
} else {
[wei408clq setToolTip:@"Weil Hall Color Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a TUR-2215-CLQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[tur2215clq setToolTip:@"Printer already Installed"];
[tur2215clq setEnabled:false];
} else {
[tur2215clq setToolTip:@"Turlington Hall Room 2215 Color Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
// Black and White Printers
myFD = popen("lpstat -a ARC-ATLAB-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[arcatlabbwq setToolTip:@"Printer already Installed"];
[arcatlabbwq setEnabled:false];
} else {
[arcatlabbwq setToolTip:@"Architecture Black and White Printers (Rooms 116 and 118)"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a B105-110-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[b105110bwq setToolTip:@"Printer already Installed"];
[b105110bwq setEnabled:false];
} else {
[b105110bwq setToolTip:@"Building 105 Room 110 Black and White Printers"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a CSE-211-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[cse211bwq setToolTip:@"Printer already Installed"];
[cse211bwq setEnabled:false];
} else {
[cse211bwq setToolTip:@"CSE Black and White Printers (Rooms 211A and 211)"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a HSC-MDL-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[hscmdlbwq setToolTip:@"Printer already Installed"];
[hscmdlbwq setEnabled:false];
} else {
[hscmdlbwq setToolTip:@"The Black and White Printers for the Medical Science Center"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a HUB-ATLAB-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[hubatlabbwq setToolTip:@"Printer already Installed"];
[hubatlabbwq setEnabled:false];
} else {
[hubatlabbwq setToolTip:@"Hub Black and White Printers (Rooms 120 and 224)"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a LAW-PCLAB-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[lawpclabbwq setToolTip:@"Printer already Installed"];
[lawpclabbwq setEnabled:false];
} else {
[lawpclabbwq setToolTip:@"Law Library Black and White Printers"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a LBW-3RAD-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[lbw3radbwq setToolTip:@"Printer already Installed"];
[lbw3radbwq setEnabled:false];
} else {
[lbw3radbwq setToolTip:@"West Library Black and White Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a NRN-ATLAB-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[nrnatlabbwq setToolTip:@"Printer already Installed"];
[nrnatlabbwq setEnabled:false];
} else {
[nrnatlabbwq setToolTip:@"Norman Hall Black and White Printers (Rooms G512, G514 and G514I)"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a TUR-2215-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[tur2215bwq setToolTip:@"Printer already Installed"];
[tur2215bwq setEnabled:false];
} else {
[tur2215bwq setToolTip:@"Turlington Hall Room 2215 Black and White Printer"];
}
strcpy(buffer, " ");
pclose(myFD);
myFD = popen("lpstat -a WEI-ATLAB-BWQ | grep -o \"accepting\"","r");
fgets (buffer, 10, myFD);
//checks if the output of buffer is accepting then it will not allow the printer to be selected. Also sets the tooltips for each printer
if (strncmp (buffer,"accepting", 9) == 0) {
[weiatlabbwq setToolTip:@"Printer already Installed"];
[weiatlabbwq setEnabled:false];
} else {
[weiatlabbwq setToolTip:@"Weil Hall Black and White Printers (Rooms 408, 410, and 412)"];
}
strcpy(buffer, " ");
pclose(myFD);
}
@end