Adium

Changeset 23478

Show
Ignore:
Timestamp:
05/17/2008 06:51:06 PM (7 months ago)
Author:
zacw
Message:

Save and restore opened chats/containers when Adium quits. This is a preference in the General preferences. I'm going to eventually also have it save and restore the HTML of the webkit view, but that's going to take a little bit of thinking. Fixes #8360.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/Adium Framework/Source/AIInterfaceControllerProtocol.h

    r23390 r23478  
    2525#define KEY_TABBED_CHATTING                             @"Tabbed Chatting" 
    2626#define KEY_GROUP_CHATS_BY_GROUP                @"Group Chats By Group" 
     27#define KEY_SAVE_CONTAINERS                             @"Save Containers On Quit" 
     28#define KEY_CONTAINERS                                  @"Containers" 
    2729 
    2830#define PREF_GROUP_CONTACT_LIST                         @"Contact List" 
     
    442444 *      Key                     Value 
    443445 *      @"ID"           NSString of the containerID 
     446 *  @"Frame"    NSString of the window's [NSWindow frame] 
    444447 *      @"Content"      NSArray of the AIChat objects within that container 
    445448 *      @"Name"         NSString of the container's name 
  • trunk/Plugins/Dual Window Interface/AIDualWindowInterfacePlugin.m

    r23389 r23478  
    172172 *      Key                     Value 
    173173 *      @"ID"           NSString of the containerID 
     174 *  @"Frame"    NSString of the window's [NSWindow frame] 
    174175 *      @"Content"      NSArray of the AIChat objects within that container 
    175176 *      @"Name"         NSString of the container's name 
     
    183184        while ((container = [containerEnumerator nextObject])) { 
    184185                [openContainersAndChats addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
    185                         [container containerID], @"ID", 
    186                         [container containedChats], @"Content", 
    187                         [container name], @"Name", 
    188                         nil]]; 
     186                                                                                   [container containerID], @"ID", 
     187                                                                                   NSStringFromRect([[container window] frame]), @"Frame", 
     188                                                                                   [container containedChats], @"Content", 
     189                                                                                   [container name], @"Name", 
     190                                                                                   nil]]; 
    189191        } 
    190192         
  • trunk/Resources/en.lproj/GeneralPreferences.nib/classes.nib

    r22854 r23478  
    5151                                <key>prefsWindowWillClose</key> 
    5252                                <string>SS_PrefsController</string> 
     53                                <key>toggleFindPanel</key> 
     54                                <string>id</string> 
    5355                                <key>willAdjustSubviews</key> 
    5456                                <string>RBSplitView</string> 
  • trunk/Resources/en.lproj/GeneralPreferences.nib/info.nib

    r22854 r23478  
    1414        </array> 
    1515        <key>IBSystem Version</key> 
    16         <string>9C31</string> 
     16        <string>9C7010</string> 
    1717        <key>targetFramework</key> 
    1818        <string>IBCocoaFramework</string> 
  • trunk/Source/AIInterfaceController.h

    r20924 r23478  
    7575                 
    7676        BOOL                                            groupChatsByContactGroup; 
     77        BOOL                                            saveContainers; 
    7778         
    7879        NSMenuItem                                      *menuItem_toggleUserlist; 
  • trunk/Source/AIInterfaceController.m

    r23389 r23478  
    1919#import "AIInterfaceController.h" 
    2020 
     21#import <Adium/AIAccountControllerProtocol.h> 
    2122#import <Adium/AIContactControllerProtocol.h> 
    2223#import <Adium/AIChatControllerProtocol.h> 
     
    6566- (void)updateCloseMenuKeys; 
    6667 
     68- (void)saveContainers; 
     69- (void)restoreSavedContainers; 
     70 
    6771//Window Menu 
    6872- (void)updateActiveWindowMenuItem; 
     
    161165        //Open the contact list window 
    162166    [self showContactList:nil]; 
    163  
     167         
    164168        //Userlist show/hide item 
    165169        menuItem_toggleUserlist = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"Toggle User List", nil) 
     
    192196                                                                           name:CONTENT_MESSAGE_RECEIVED object:nil]; 
    193197    [[adium notificationCenter] addObserver:self selector:@selector(didReceiveContent:)  
    194                                                                            name:CONTENT_MESSAGE_RECEIVED_GROUP object:nil];      
     198                                                                           name:CONTENT_MESSAGE_RECEIVED_GROUP object:nil]; 
     199         
     200        //Observe quits so we can save containers. 
     201        [[adium notificationCenter] addObserver:self 
     202                                                                   selector:@selector(saveContainers) 
     203                                                                           name:AIAppWillTerminateNotification 
     204                                                                         object:nil]; 
    195205} 
    196206 
     
    241251        tabbedChatting = [[prefDict objectForKey:KEY_TABBED_CHATTING] boolValue]; 
    242252        groupChatsByContactGroup = [[prefDict objectForKey:KEY_GROUP_CHATS_BY_GROUP] boolValue]; 
     253        saveContainers = [[prefDict objectForKey:KEY_SAVE_CONTAINERS] boolValue]; 
     254         
     255        if (saveContainers && firstTime) { 
     256                //Restore saved containers 
     257                [self restoreSavedContainers];   
     258        } 
    243259} 
    244260 
     
    350366 * @returns Created contact list controller for detached contact list 
    351367 */ 
    352 - (AIListWindowController *)detachContactList:(AIListGroup *)aContactList { 
     368- (AIListWindowController *)detachContactList:(AIListGroup *)aContactList 
     369
    353370        return [contactListPlugin detachContactList:aContactList]; 
    354371} 
    355372 
     373 
     374#pragma mark Container Saving 
     375/*! 
     376 * @brief Restores containers saved from a previous session 
     377 */ 
     378- (void)restoreSavedContainers 
     379{ 
     380        NSData                          *savedData = [[adium preferenceController] preferenceForKey:KEY_CONTAINERS 
     381                                                                                                                                        group:PREF_GROUP_INTERFACE]; 
     382         
     383        // If there's no data, we can't restore anything. 
     384        if (!savedData) 
     385                return; 
     386 
     387        NSEnumerator            *enumerator = [[NSKeyedUnarchiver unarchiveObjectWithData:savedData] objectEnumerator]; 
     388        NSDictionary            *dict; 
     389         
     390        while ((dict = [enumerator nextObject])) { 
     391                AIMessageWindowController *windowController = [self openContainerWithID:[dict objectForKey:@"ID"] 
     392                                                                                                                                 name:[dict objectForKey:@"Name"]]; 
     393                 
     394                NSEnumerator                    *chatEnumerator = [[dict objectForKey:@"Content"] objectEnumerator]; 
     395                NSDictionary                    *chatDict; 
     396                 
     397                while ((chatDict = [chatEnumerator nextObject])) { 
     398                        AIChat                  *chat = nil; 
     399                        AIService               *service = [[adium accountController] firstServiceWithServiceID:[chatDict objectForKey:@"serviceID"]]; 
     400                        AIAccount               *account = [[adium accountController] accountWithInternalObjectID:[chatDict objectForKey:@"AccountID"]]; 
     401                                 
     402                        if ([[chatDict objectForKey:@"IsGroupChat"] boolValue]) { 
     403                                chat = [[adium chatController] chatWithName:[chatDict objectForKey:@"Name"] 
     404                                                                                                 identifier:nil 
     405                                                                                                  onAccount:account 
     406                                                                                   chatCreationInfo:[chatDict objectForKey:@"ChatCreationInfo"]]; 
     407                        } else { 
     408                                AIListContact           *contact = [[adium contactController] contactWithService:service 
     409                                                                                                                                                                account:account 
     410                                                                                                                                                                        UID:[chatDict objectForKey:@"UID"]]; 
     411                                 
     412                                chat = [[adium chatController] chatWithContact:contact]; 
     413                        } 
     414                         
     415                        // Open the chat into the container we've created above. 
     416                        [self openChat:chat inContainerWithID:[dict objectForKey:@"ID"] atIndex:-1]; 
     417                } 
     418         
     419                // Position the container where it was last saved (using -savedFrameFromString: to prevent going offscreen) 
     420                [[windowController window] setFrame:[windowController savedFrameFromString:[dict objectForKey:@"Frame"]] display:YES]; 
     421        } 
     422} 
     423 
     424/*! 
     425 * @brief Saves open container information when Adium quits 
     426 */ 
     427- (void)saveContainers 
     428{ 
     429        // If we're quitting with containers unsaved, be sure to reset the possibly-formerly-valid information to nil 
     430        // We don't do this upon unchecking the preference so that it isn't a permanent removal of the saved information until 
     431        // end of session. 
     432        if (!saveContainers) { 
     433                [[adium preferenceController] setPreference:nil 
     434                                                                                         forKey:KEY_CONTAINERS 
     435                                                                                          group:PREF_GROUP_INTERFACE]; 
     436                return; 
     437        } 
     438         
     439        // Save active containers. 
     440        NSMutableArray          *savedContainers = [NSMutableArray array]; 
     441        NSEnumerator            *enumerator = [[interfacePlugin openContainersAndChats] objectEnumerator]; 
     442        NSDictionary            *dict; 
     443         
     444        while ((dict = [enumerator nextObject])) { 
     445                NSMutableArray          *containerContents = [NSMutableArray array];             
     446                NSEnumerator            *containedEnumerator = [[dict objectForKey:@"Content"] objectEnumerator]; 
     447                AIChat                          *chat; 
     448                 
     449                while ((chat = [containedEnumerator nextObject])) { 
     450                        if ([chat isOpen]) { 
     451                                if ([chat isGroupChat]) { 
     452                                        // -chatCreationDictionary may be nil, so put it last. 
     453                                        [containerContents addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
     454                                                                                                  [NSNumber numberWithBool:YES], @"IsGroupChat", 
     455                                                                                                  [chat name], @"Name", 
     456                                                                                                  [[chat account] internalObjectID], @"AccountID", 
     457                                                                                                  [chat chatCreationDictionary], @"ChatCreationInfo",nil]]; 
     458                                } else { 
     459                                        [containerContents addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
     460                                                                                                  [[chat listObject] UID], @"UID", 
     461                                                                                                  [[chat listObject] serviceID], @"serviceID", 
     462                                                                                                  [[chat account] internalObjectID], @"AccountID",nil]]; 
     463                                } 
     464                        } 
     465                } 
     466                 
     467                // Replace the "Content" key in -openContainersAndChats with our version of the content. 
     468                // We use the same keys otherwise that -openContainersAndChats provides (Name, ID, Frame) 
     469                NSMutableDictionary *saveDict = [[dict mutableCopy] autorelease]; 
     470                 
     471                [saveDict setObject:containerContents 
     472                                         forKey:@"Content"]; 
     473                 
     474                [savedContainers addObject:saveDict]; 
     475        } 
     476         
     477        [[adium preferenceController] setPreference:[NSKeyedArchiver archivedDataWithRootObject:savedContainers] 
     478                                                                                 forKey:KEY_CONTAINERS 
     479                                                                                  group:PREF_GROUP_INTERFACE]; 
     480} 
    356481 
    357482//Messaging ------------------------------------------------------------------------------------------------------------