#import "BPMailImporter.h" #import "BPMailAppData.h" #import "BPDocumentGroup.h" #import "BPPilesDataController.h" #import "BPMailboxBrowserController.h" #import "BPAppController.h" #import "BPPilesDisplayController.h" @implementation BPMailImporter - (void)awakeFromNib { [mailboxBrowser setDelegate:mailboxBrowserController]; [mailboxBrowser setTarget:self]; [mailboxBrowser setAction:@selector(selectedBrowserCell:)]; [mailboxBrowser setDoubleAction:@selector(doubleClicked:)]; } - (IBAction)doubleClicked:(id)sender { if ([mailboxBrowser lastColumn] != nil && [mailboxBrowser selectedColumn] == [mailboxBrowser lastColumn]) { [self completeImport:sender]; } } - (IBAction)selectedBrowserCell:(id)sender { if ([mailboxBrowser selectedColumn] == [mailboxBrowser lastColumn]) { [importButton setEnabled:YES]; [importButton highlight:YES]; } else { [importButton setEnabled:NO]; [importButton highlight:NO]; } } - (IBAction)startImport:(id)sender { //[[NSApplication sharedApplication] runModalForWindow:importPanel]; [importPanel makeKeyAndOrderFront:nil]; } - (IBAction)cancelImport:(id)sender { //[[NSApplication sharedApplication] abortModal]; [importPanel close]; } // complete the import procedure - (IBAction)completeImport:(id)sender { NSLog(@"completeImport on %@", [[mailboxBrowser selectedCell] stringValue]); [mailAppData importEmailDocumentsForMailInAccount:[mailboxBrowser selectedRowInColumn:0] mailbox:[mailboxBrowser selectedRowInColumn:1] mailCount:[importCount intValue] target:self action:@selector(importedMail:)]; } // callback function - (void)importedMail:(NSArray *)importedMail { BPDocumentGroup *existingPile = [pileDataController pileWithName:[[mailboxBrowser selectedCell] stringValue]]; BPDocumentGroup *destPile; if (existingPile == nil) { // make a document group (pile) from the newly imported mail BPDocumentGroup *newGroup = [BPDocumentGroup groupWithLabel:[[mailboxBrowser selectedCell] stringValue] atPosition:NSZeroPoint documents:importedMail]; // send the new group of emails to the pile data controller, who will tell // the display to show the new pile [pileDataController addNewPile:newGroup]; destPile = newGroup; } else { // add mail to existing pile int i; for (i=0; i<[importedMail count]; i++) { [pileDataController addPileDocument:[importedMail objectAtIndex:i] toPile:existingPile]; } destPile = existingPile; } // save newly generated favicons [appController saveFavicons]; // close panel //[[NSApplication sharedApplication] stopModal]; [importPanel close]; [pilesDisplayController refreshDisplayForPile:destPile]; } - (void)dealloc { NSLog(@"destroying %@", self); [mailboxBrowserController release]; [super dealloc]; } @end