Adium

Changeset 23481

Show
Ignore:
Timestamp:
05/17/2008 11:21:00 PM (7 months ago)
Author:
zacw
Message:

Save and restore the buffered HTML contents of chats along with their containers. This exposes a few things: <AIMessageDisplayController> gain a way to set or get the contents of the "content source"—whatever arbitrary NSString representation of the view they want to store. This is passed back in to "restore" the last save. This also includes a mechanism to state the version/implementation of the "source" so that it doesn't restore the wrong info (i.e., style changes—styles are the identifier for the webkit view). AIMessageView gains a mechanism to reveal its <AIMessageDisplayController>.

Someone more familiar with WebKit stuff able to tell me why it doesn't scroll to the bottom where it's set to do so in AIWebKitMessageViewController.m?

Refs #8360.

Files:

Legend:

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

    r23478 r23481  
    396396 */ 
    397397@protocol AIMessageDisplayController <NSObject> 
     398- (void)setChatContentSource:(NSString *)source; 
     399- (NSString *)chatContentSource; 
     400- (NSString *)contentSourceName; // Unique name for this particular style of "content source". 
     401 
    398402- (NSView *)messageView; 
    399403- (NSView *)messageScrollView; 
  • trunk/Plugins/Dual Window Interface/AIMessageViewController.h

    r23084 r23481  
    7979 
    8080//Message Display 
     81- (NSObject<AIMessageDisplayController> *)messageDisplayController; 
    8182- (NSView *)view; 
    8283- (void)adiumPrint:(id)sender; 
  • trunk/Plugins/Dual Window Interface/AIMessageViewController.m

    r23404 r23481  
    372372 
    373373        [controllerView_messages setNextResponder:textView_outgoing]; 
     374} 
     375 
     376/*! 
     377 * @brief The message display controller 
     378 */ 
     379- (NSObject<AIMessageDisplayController> *)messageDisplayController 
     380{ 
     381        return messageDisplayController; 
    374382} 
    375383 
  • trunk/Plugins/WebKit Message View/AIWebKitMessageViewController.h

    r22467 r23481  
    1 /*  
     1 /*  
    22 * Adium is the legal property of its developers, whose names are listed in the copyright file included 
    33 * with this source distribution. 
     
    9797- (void)setShouldReflectPreferenceChanges:(BOOL)inValue; 
    9898 
     99/*! 
     100 * @brief Set the HTML content for the "Chat" area. 
     101 */ 
     102- (void)setChatContentSource:(NSString *)source; 
     103 
     104/*! 
     105 * @brief Get the HTML content for the "Chat" area. 
     106 */ 
     107- (NSString *)chatContentSource; 
     108 
    99109- (void)setPreferencesChangedDelegate:(id)inDelegate; 
    100110@end 
  • trunk/Plugins/WebKit Message View/AIWebKitMessageViewController.m

    r23300 r23481  
    13581358} 
    13591359 
     1360/*! 
     1361 * @brief Set the HTML content for the "Chat" area. 
     1362 */ 
     1363- (void)setChatContentSource:(NSString *)source 
     1364{ 
     1365        if (!webViewIsReady) { 
     1366                // If the webview isn't ready yet, wait a very short amount of time before trying again 
     1367                [self performSelector:@selector(setChatContentSource:) 
     1368                                   withObject:source 
     1369                                   afterDelay:0.01]; 
     1370        } else { 
     1371                // Add the old "Chat" element to the window. 
     1372                [(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] getElementById:@"Chat"] setOuterHTML:source]; 
     1373 
     1374                NSString        *scrollToBottomScript;           
     1375                if ((scrollToBottomScript = [messageStyle scriptForScrollingAfterAddingMultipleContentObjects])) { 
     1376                        [webView stringByEvaluatingJavaScriptFromString:scrollToBottomScript]; 
     1377                } 
     1378        } 
     1379} 
     1380 
     1381/*! 
     1382 * @brief Get the HTML content for the "Chat" area. 
     1383 */ 
     1384- (NSString *)chatContentSource 
     1385{ 
     1386        return [(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] getElementById:@"Chat"] outerHTML]; 
     1387} 
     1388 
     1389/*! 
     1390 * @brief The unique name for this style of "content source" 
     1391 */ 
     1392- (NSString *)contentSourceName 
     1393{ 
     1394        return [[[messageStyle bundle] bundlePath] lastPathComponent]; 
     1395} 
     1396 
    13601397@end 
  • trunk/Source/AIInterfaceController.h

    r23478 r23481  
    1818#import <Adium/AIAdiumProtocol.h> 
    1919 
    20 @class AIMenuController, AIChat, AIListObject
     20@class AIMenuController, AIChat, AIListObject, AIMessageViewController
    2121 
    2222@interface AIInterfaceController : NSObject <AIInterfaceController> { 
  • trunk/Source/AIInterfaceController.m

    r23478 r23481  
    4444#import <Adium/AIServiceIcons.h> 
    4545#import <Adium/AISortController.h> 
     46#import "AIMessageTabViewItem.h" 
    4647#import "KFTypeSelectTableView.h" 
    4748#import <KNShelfSplitview.h> 
     49 
     50#import "AIMessageViewController.h" 
    4851 
    4952#define ERROR_MESSAGE_WINDOW_TITLE              AILocalizedString(@"Adium : Error","Error message window title") 
     
    256259                //Restore saved containers 
    257260                [self restoreSavedContainers];   
     261        } else if (!saveContainers) { 
     262                [[adium preferenceController] setPreference:nil 
     263                                                                                         forKey:KEY_CONTAINERS 
     264                                                                                          group:PREF_GROUP_INTERFACE]; 
    258265        } 
    259266} 
     
    414421                         
    415422                        // Open the chat into the container we've created above. 
    416                         [self openChat:chat inContainerWithID:[dict objectForKey:@"ID"] atIndex:-1]; 
     423                        AIMessageTabViewItem *tabViewItem = [self openChat:chat inContainerWithID:[dict objectForKey:@"ID"] atIndex:-1]; 
     424                         
     425                        // Restore the display buffer of the chat. 
     426                        NSObject<AIMessageDisplayController>    *displayController = [(AIMessageViewController *)[tabViewItem messageViewController] messageDisplayController]; 
     427                         
     428                        // Only load the old content if the content name is the same. 
     429                        if ([[displayController contentSourceName] isEqualToString:[chatDict objectForKey:@"ChatContentsName"]]) { 
     430                                [displayController setChatContentSource:[chatDict objectForKey:@"ChatContents"]]; 
     431                        } 
    417432                } 
    418433         
     
    431446        // end of session. 
    432447        if (!saveContainers) { 
    433                 [[adium preferenceController] setPreference:nil 
    434                                                                                          forKey:KEY_CONTAINERS 
    435                                                                                           group:PREF_GROUP_INTERFACE]; 
    436448                return; 
    437449        } 
     
    443455         
    444456        while ((dict = [enumerator nextObject])) { 
    445                 NSMutableArray          *containerContents = [NSMutableArray array];            
     457                NSMutableArray          *containerContents = [NSMutableArray array]; 
    446458                NSEnumerator            *containedEnumerator = [[dict objectForKey:@"Content"] objectEnumerator]; 
    447459                AIChat                          *chat; 
    448460                 
    449461                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                                 } 
     462                        NSMutableDictionary             *newContainerDict = [NSMutableDictionary dictionary]; 
     463                         
     464                        // Save the current display buffer. 
     465                        NSObject<AIMessageDisplayController>    *displayController = [(AIMessageViewController *)[(AIMessageTabViewItem *)[chat statusObjectForKey:@"MessageTabViewItem"] messageViewController] messageDisplayController]; 
     466                        [newContainerDict setObject:[displayController chatContentSource] 
     467                                                                 forKey:@"ChatContents"]; 
     468                         
     469                        [newContainerDict setObject:[displayController contentSourceName] 
     470                                                                 forKey:@"ChatContentsName"]; 
     471                         
     472                        [newContainerDict setObject:[[chat account] internalObjectID] forKey:@"AccountID"]; 
     473 
     474                        // Save chat-specific information. 
     475                        if ([chat isGroupChat]) { 
     476                                // -chatCreationDictionary may be nil, so put it last. 
     477                                [newContainerDict addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
     478                                                                                                                        [NSNumber numberWithBool:YES], @"IsGroupChat", 
     479                                                                                                                        [chat name], @"Name", 
     480                                                                                                                        [chat chatCreationDictionary], @"ChatCreationInfo",nil]]; 
     481                        } else { 
     482                                [newContainerDict addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
     483                                                                                                                        [[chat listObject] UID], @"UID", 
     484                                                                                                                        [[chat listObject] serviceID], @"serviceID", 
     485                                                                                                                        [[chat account] internalObjectID], @"AccountID",nil]]; 
    464486                        } 
     487                         
     488                        [containerContents addObject:newContainerDict]; 
    465489                } 
    466490