Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(153)

Side by Side Diff: Source/EmUpWindowController.m

Issue 198082: Add support for Entourage export files Base URL: http://google-email-uploader-mac.googlecode.com/svn/trunk/
Patch Set: formatting tweaks Created 15 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/EmUpWindowController.h ('k') | Source/English.lproj/Localizable.strings » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2009 Google Inc. 1 /* Copyright (c) 2009 Google Inc.
2 * 2 *
3 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. 4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at 5 * You may obtain a copy of the License at
6 * 6 *
7 * http://www.apache.org/licenses/LICENSE-2.0 7 * http://www.apache.org/licenses/LICENSE-2.0
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software 9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS, 10 * distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 15 matching lines...) Expand all
26 NSString *const kTabViewItemSelection = @"Selection"; 26 NSString *const kTabViewItemSelection = @"Selection";
27 NSString *const kTabViewItemProgress = @"Progress"; 27 NSString *const kTabViewItemProgress = @"Progress";
28 NSString *const kTabViewItemSkipped = @"Skipped"; 28 NSString *const kTabViewItemSkipped = @"Skipped";
29 29
30 @interface EmUpWindowController (PrivateMethods) 30 @interface EmUpWindowController (PrivateMethods)
31 - (GDataServiceGoogle *)service; 31 - (GDataServiceGoogle *)service;
32 32
33 - (void)updateUI; 33 - (void)updateUI;
34 - (NSString *)displayTimeForSeconds:(unsigned int)seconds; 34 - (NSString *)displayTimeForSeconds:(unsigned int)seconds;
35 35
36 - (void)addMailboxesAtPath:(NSString *)path typeTag:(int)tag;
37
36 // "backing off" happens when we get a status 503 on an entry; 38 // "backing off" happens when we get a status 503 on an entry;
37 // delays happen normally to keep our upload throttled to 39 // delays happen normally to keep our upload throttled to
38 // 1 message per second (in slow upload mode) 40 // 1 message per second (in slow upload mode)
39 - (void)uploadNow; 41 - (void)uploadNow;
40 - (void)uploadMoreMessages; 42 - (void)uploadMoreMessages;
41 - (void)uploadMoreMessagesAfterBackingOff; 43 - (void)uploadMoreMessagesAfterBackingOff;
42 - (void)uploadMoreMessagesAfterDelay:(NSTimeInterval)delay; 44 - (void)uploadMoreMessagesAfterDelay:(NSTimeInterval)delay;
43 - (void)cancelUploadMoreMessagesAfterDelay; 45 - (void)cancelUploadMoreMessagesAfterDelay;
44 46
45 - (void)uploadEntry:(GDataEntryMailItem *)entry; 47 - (void)uploadEntry:(GDataEntryMailItem *)entry;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 453
452 [outlineView_ reloadData]; 454 [outlineView_ reloadData];
453 [outlineView_ display]; 455 [outlineView_ display];
454 } 456 }
455 } 457 }
456 } 458 }
457 459
458 [self endingLoadingMailboxes]; 460 [self endingLoadingMailboxes];
459 } 461 }
460 462
461 // addMailboxes is sent by menu items with a tag of 0 (Apple) or 1 (mbox) 463 enum {
464 // kinds of mail folders
465 kAppleMailTag = 0,
466 kMBoxTag = 1, // mbox files
467 kMaildirTag = 2, // Maildir directories and dot subdirectories
468 kEntourageRGETag = 3
469 };
470
471 - (IBAction)importRGEArchiveFromEntourage:(id)sender {
472 // if we previously exported the rge archive, remove it and make a fresh
473 // export
474 NSFileManager *fileManager = [NSFileManager defaultManager];
475 if ([fileManager fileExistsAtPath:@"/tmp/EntourageArchive.rge"]) {
476 [fileManager removeFileAtPath:@"/tmp/EntourageArchive.rge"
477 handler:nil];
478 }
479
480 // execute a script to create an export archive package in /tmp, and report
481 // any errors
482 NSString *str = @"tell application \"Microsoft Entourage\" "
483 "to export archive to \"/tmp/EntourageArchive.rge\" "
484 "item types (mail items)";
485
486 NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:str] autoreleas e];
487 NSDictionary *errorDict = nil;
488 [script executeAndReturnError:&errorDict];
489
490 if (errorDict) {
491 NSString *title = NSLocalizedString(@"RGEImportFailed", nil);
492 NSString *msg = [errorDict objectForKey:NSAppleScriptErrorMessage];
493 NSBeginAlertSheet(title, nil, nil, nil,
494 [self window], self, NULL,
495 nil, nil, msg);
496 return;
497 }
498
499 // add the exported directory's Mail folder as the folder containing mbox
500 // files
501 NSString *path = @"/tmp/EntourageArchive.rge/Mail";
502 [self addMailboxesAtPath:path
503 typeTag:kEntourageRGETag];
TVL 2010/02/03 05:16:01 does it make sense to do anything (special type?)
504 }
505
506 // addMailboxes is sent by menu items with a tag for the kind of mailbox to add
462 - (IBAction)addMailboxes:(id)sender { 507 - (IBAction)addMailboxes:(id)sender {
463
464 if (isUploading_) return; 508 if (isUploading_) return;
465 509
466 int tag = [sender tag]; 510 int tag = [sender tag];
467 511
468 NSOpenPanel *panel = [NSOpenPanel openPanel]; 512 NSOpenPanel *panel = [NSOpenPanel openPanel];
513 [panel setPrompt:NSLocalizedString(@"SelectButton", nil)]; // "Select"
469 514
470 [panel setCanChooseDirectories:YES]; 515 NSArray *types = nil;
471 [panel setCanChooseFiles:NO]; 516 if (tag == kEntourageRGETag) {
472 [panel setPrompt:NSLocalizedString(@"SelectButton", nil)]; // "Select" 517 // select "files" with extension rge, though it's really a package directory
473 [panel setMessage:NSLocalizedString(@"SelectTitle", nil)]; // "Select Mail Dir ectory" 518 [panel setCanChooseDirectories:NO];
519 [panel setCanChooseFiles:YES];
520 [panel setMessage:NSLocalizedString(@"SelectRGETitle", nil)]; // "Select rge file"
521 types = [NSArray arrayWithObject:@"rge"];
522 } else {
523 // select any folder
524 [panel setCanChooseDirectories:YES];
525 [panel setCanChooseFiles:NO];
526 [panel setMessage:NSLocalizedString(@"SelectTitle", nil)]; // "Select Mail D irectory"
527 }
474 528
475 [panel beginSheetForDirectory:nil 529 [panel beginSheetForDirectory:nil
476 file:nil 530 file:nil
531 types:types
477 modalForWindow:[self window] 532 modalForWindow:[self window]
478 modalDelegate:self 533 modalDelegate:self
479 didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo :) 534 didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo :)
480 contextInfo:(void *)tag]; 535 contextInfo:(void *)tag];
481 } 536 }
482 537
483 - (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode context Info:(void *)contextInfo { 538 - (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode context Info:(void *)contextInfo {
484 539
485 if (returnCode != NSOKButton) return; 540 if (returnCode != NSOKButton) return;
486 541
487 enum {
488 // kinds of mail folders
489 kAppleMailTag = 0,
490 kMBoxTag = 1, // mbox files
491 kMaildirTag = 2 // Maildir directories and dot subdirectories
492 };
493
494 int tag = (int)contextInfo; 542 int tag = (int)contextInfo;
495 543
496 NSString *path = [panel filename]; 544 NSString *path = [panel filename];
545 ··
546 if (tag == kEntourageRGETag) {
547 // look in the Mail subdirectory of the Entourage archive; from there,
548 // it's all mbox directories
549 path = [path stringByAppendingPathComponent:@"Mail"];·
550 }
551
552 [self addMailboxesAtPath:path
553 typeTag:tag];
554 }
555
556 - (void)addMailboxesAtPath:(NSString *)path typeTag:(int)tag {
557
497 NSString *shortPath = [path stringByAbbreviatingWithTildeInPath]; 558 NSString *shortPath = [path stringByAbbreviatingWithTildeInPath];
498 NSString *longPath = [path stringByStandardizingPath]; 559 NSString *longPath = [path stringByStandardizingPath];
499 560
500 [self beginningLoadingMailboxes]; 561 [self beginningLoadingMailboxes];
501 562
502 // the user picked a menu item for adding new mail directories to scan 563 // the user picked a menu item for adding new mail directories to scan
503 NSString *template; 564 NSString *template;
504 switch(tag) { 565 switch(tag) {
505 566
506 case kAppleMailTag: { 567 case kAppleMailTag: {
507 template = NSLocalizedString(@"AppleMailPathTemplate", nil); // "Apple Mai l - %@" 568 template = NSLocalizedString(@"AppleMailPathTemplate", nil); // "Apple Mai l - %@"
508 NSString *appleRootName = [NSString stringWithFormat:template, shortPath]; 569 NSString *appleRootName = [NSString stringWithFormat:template, shortPath];
509 570
510 AppleMailItemsController *appleMail; 571 AppleMailItemsController *appleMail;
511 appleMail = [[[AppleMailItemsController alloc] initWithMailFolderPath:long Path 572 appleMail = [[[AppleMailItemsController alloc] initWithMailFolderPath:long Path
512 rootName:appl eRootName 573 rootName:appl eRootName
513 isMaildir:NO] autorelease]; 574 isMaildir:NO] autorelease];
514 [itemsControllers_ addObject:appleMail]; 575 [itemsControllers_ addObject:appleMail];
515 break; 576 break;
516 } 577 }
517 578
579 case kEntourageRGETag:
518 case kMBoxTag: { 580 case kMBoxTag: {
519 template = NSLocalizedString(@"MBoxPathTemplate", nil); // "MBox - %@" 581 if (tag == kMBoxTag) {
582 template = NSLocalizedString(@"MBoxPathTemplate", nil); // "MBox - %@"
583 } else {
584 // "Entourage - %@"
585 template = NSLocalizedString(@"EntouragePathTemplate", nil);
586 }
520 NSString *macRootName = [NSString stringWithFormat:template, shortPath]; 587 NSString *macRootName = [NSString stringWithFormat:template, shortPath];
521 MBoxItemsController *mbox; 588 MBoxItemsController *mbox;
522 mbox = [[[MBoxItemsController alloc] initWithMailFolderPath:longPath 589 mbox = [[[MBoxItemsController alloc] initWithMailFolderPath:longPath
523 rootName:macRootName] a utorelease]; 590 rootName:macRootName] a utorelease];
524 [itemsControllers_ addObject:mbox]; 591 [itemsControllers_ addObject:mbox];
525 break; 592 break;
526 } 593 }
527 594
528 case kMaildirTag: { 595 case kMaildirTag: {
529 template = NSLocalizedString(@"MaildirPathTemplate", nil); // "Maildir - % @" 596 template = NSLocalizedString(@"MaildirPathTemplate", nil); // "Maildir - % @"
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 - (void)setLastUploadDate:(NSDate *)date { 1596 - (void)setLastUploadDate:(NSDate *)date {
1530 [lastUploadDate_ release]; 1597 [lastUploadDate_ release];
1531 lastUploadDate_ = [date retain]; 1598 lastUploadDate_ = [date retain];
1532 } 1599 }
1533 1600
1534 - (void)setSimulateUploads:(BOOL)flag { 1601 - (void)setSimulateUploads:(BOOL)flag {
1535 shouldSimulateUploads_ = flag; 1602 shouldSimulateUploads_ = flag;
1536 } 1603 }
1537 1604
1538 @end 1605 @end
OLDNEW
« no previous file with comments | « Source/EmUpWindowController.h ('k') | Source/English.lproj/Localizable.strings » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b