From c72b412ec88052012405c529332f835a8265d941 Mon Sep 17 00:00:00 2001 From: Vasileios Georgitzikis Date: Wed, 28 Jul 2010 18:12:50 +0000 Subject: [PATCH] Added fetching of variants conflicts in the GUI, when the user clicks on Install With Variants git-svn-id: https://svn.macports.org/repository/macports/branches/gsoc10-gui@70052 d073be05-634f-4543-b044-5fe20cf6d1d6 --- Pallet/MPActionsController.h | 1 + Pallet/MPActionsController.m | 83 +++++++++++++++++++++++++++++++++--- Pallet/MPCheckbox.h | 4 +- Pallet/MPCheckbox.m | 8 ---- 4 files changed, 81 insertions(+), 15 deletions(-) diff --git a/Pallet/MPActionsController.h b/Pallet/MPActionsController.h index 1cb322a..f01c4e1 100644 --- a/Pallet/MPActionsController.h +++ b/Pallet/MPActionsController.h @@ -60,6 +60,7 @@ extern BOOL altWasPressed; - (IBAction)toggleInfoPanel: (id) sender; -(IBAction)clickCheckbox:(id)sender; +-(void)checkConflicts: (NSString*) portName; - (void)queueOperation: (NSString*) operation portName: (NSString*) name portObject: (id) port variants: (NSMutableArray*) variants; diff --git a/Pallet/MPActionsController.m b/Pallet/MPActionsController.m index 6642292..b9d9ff3 100644 --- a/Pallet/MPActionsController.m +++ b/Pallet/MPActionsController.m @@ -91,6 +91,7 @@ //Testing code //checkboxes[0].conflictsWith = @"universal"; + for(UInt i=0; i< 10;i++) { [checkboxes[i] setAlphaValue:0]; @@ -153,6 +154,8 @@ } //NSLog(@"End of Variants"); + [self checkConflicts:[port valueForKey:@"name"]]; + [variantsPanel makeKeyAndOrderFront:self]; //[chckbx2 setTitle:@"hehe"]; @@ -271,6 +274,7 @@ -(IBAction)clickCheckbox:(id)sender { + //Are we checking or unchecking the checkbox? BOOL enableDisable; if([sender state]==NSOnState) @@ -281,14 +285,83 @@ { enableDisable=YES; } - //Enable/disable our conflicts depending on what we are doing - for(UInt i=0; i<10; i++) + + for(UInt j=0;j<[[sender conflictsWith] count]; j++) { - if ([[checkboxes[i] title] isEqualToString:[sender conflictsWith]]) + //Enable/disable our conflicts depending on what we are doing + for(UInt i=0; i<10; i++) { - [checkboxes[i] setEnabled:enableDisable]; - } + if ([[checkboxes[i] title] isEqualToString:[[sender conflictsWith] objectAtIndex:j]]) + { + [checkboxes[i] setEnabled:enableDisable]; + if (!enableDisable) + { + [checkboxes[i] setState:NSOffState]; + } + } + } } + +} + +-(void)checkConflicts: (NSString *) portName +{ + + char *script= "pbpaste | python -c \"import re,sys;lines=sys.stdin.readlines();print '\\n'.join('%s,%s' % (re.sub(r'[\\W]','',lines[i-1].split()[0].rstrip(':')),','.join(l.strip().split()[3:])) for i, l in enumerate(lines) if l.strip().startswith('* conflicts'))\" >> mpfw_conflict"; + //char *script="'''"; + char command[256]; + strcpy(command,"port variants "); + strcat(command, [portName UTF8String]); + strcat(command, "| pbcopy"); + printf("\n%s\n%s\n", command, script); + system(command); + system(script); + + //Open the output file + FILE * file = fopen("mpfw_conflict", "r"); + + //Read all default_variants + char buffer[256]; + while(!feof(file)) + { + char * temp = fgets(buffer,256,file); + if(temp == NULL) continue; + buffer[strlen(buffer)-1]='\0'; + //Add the variant in the Array + printf("buffer:\n%s\n",buffer); + + char *token; + char *search = ","; + + token = strtok(buffer, search); + printf("token: %s\n",token); + + UInt i; + for(i=0; i<10; i++) + { + //NSLog(@"%@ %@",[checkboxes[i] title], [NSString stringWithCString:token]); + + if ([[checkboxes[i] title] isEqualToString:[NSString stringWithCString:token]]) + { + break; + } + } + [checkboxes[i] setConflictsWith:[NSMutableArray array]]; + NSLog(@"checkbox: %i",i); + while ((token = strtok(NULL, search)) != NULL) + { + NSLog(@"token: %@",[NSString stringWithCString:token]); + [[checkboxes[i] conflictsWith] addObject:[NSString stringWithCString:token]]; + //NSLog(@"count %i",[[checkboxes[i] conflictsWith] count]); + } + + //[defaultVariants addObject:[NSString stringWithCString:buffer]]; + } + //Close and delete + fclose(file); + unlink("mpfw_conflict"); + + } -(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem { diff --git a/Pallet/MPCheckbox.h b/Pallet/MPCheckbox.h index 36b99d9..654b0f0 100644 --- a/Pallet/MPCheckbox.h +++ b/Pallet/MPCheckbox.h @@ -14,10 +14,10 @@ BOOL isDefault; - NSString *conflictsWith; + NSMutableArray *conflictsWith; } @property (nonatomic) BOOL isDefault; -@property (nonatomic, retain) NSString *conflictsWith; +@property (nonatomic, retain) NSMutableArray *conflictsWith; @end diff --git a/Pallet/MPCheckbox.m b/Pallet/MPCheckbox.m index f674768..4a1a60b 100644 --- a/Pallet/MPCheckbox.m +++ b/Pallet/MPCheckbox.m @@ -10,13 +10,5 @@ @implementation MPCheckbox - @synthesize isDefault, conflictsWith; - --(void) performClick: (id) sender -{ - NSLog(@"performing click"); - [super performClick:sender]; - NSLog(@"click performed"); -} @end