adium 4335:e25448d743b3: Some more reworking of how the WebKit M...
commits at adium.im
commits at adium.im
Thu Dec 1 21:22:03 UTC 2011
details: http://hg.adium.im/adium/rev/e25448d743b3
revision: 4335:e25448d743b3
branch: (none)
author: Stephen Holt <sholt at adium.im>
date: Thu Dec 01 13:21:59 2011 -0800
Some more reworking of how the WebKit Message Views are configured. Fixes #15377
diffs (234 lines):
diff -r 5938f683a691 -r e25448d743b3 ChangeLogs/Changes Between Betas.txt
--- a/ChangeLogs/Changes Between Betas.txt Wed Nov 30 23:57:17 2011 -0800
+++ b/ChangeLogs/Changes Between Betas.txt Thu Dec 01 13:21:59 2011 -0800
@@ -1,6 +1,7 @@
Adium 1.5b6
* Fixed automatic updating between betas failing with the error "Can't make a temporary directory for the update download". (#15666)
* Correct strange behavior in the messages pref pane. (#15670)
+ * Further fixes of message context display. (#15377)
* Fixed a 2px alignment issue when a normal or borderless contact window is set to vertically resize automatically. (#15626)
* Restored bouncy scroll behavior to normal window style contact list windows.
* Fixed crash when sending certain group chat requests. (#15674)
diff -r 5938f683a691 -r e25448d743b3 Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m Wed Nov 30 23:57:17 2011 -0800
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m Thu Dec 01 13:21:59 2011 -0800
@@ -352,112 +352,118 @@
*/
- (void)_updateWebViewForCurrentPreferences
{
- //Cleanup first
- [messageStyle autorelease]; messageStyle = nil;
- [activeStyle release]; activeStyle = nil;
+ static dispatch_queue_t webViewUpdateQueue = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ webViewUpdateQueue = dispatch_queue_create("im.adium.AIWebKitMessageViewController.webViewUpdateQueue", 0);
+ });
- //Load the message style
- messageStyle = [[plugin currentMessageStyleForChat:chat] retain];
- activeStyle = [[[messageStyle bundle] bundleIdentifier] retain];
- preferenceGroup = [[plugin preferenceGroupForChat:chat] retain];
-
- [webView setPreferencesIdentifier:[NSString stringWithFormat:@"%@-%@",
- activeStyle, preferenceGroup]];
-
- //Get the prefered variant (or the default if a prefered is not available)
- NSString *activeVariant;
- activeVariant = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Variant" forStyle:activeStyle]
- group:preferenceGroup];
- if (!activeVariant || ![[messageStyle availableVariants] containsObject:activeVariant])
- activeVariant = [messageStyle defaultVariant];
- if (!activeVariant || ![[messageStyle availableVariants] containsObject:activeVariant]) {
- /* If the message style doesn't specify a default variant, choose the first one.
- * Note: Old styles (styleVersion < 3) will always report a variant for defaultVariant.
- */
- NSArray *availableVariants = [messageStyle availableVariants];
- if ([availableVariants count]) {
- activeVariant = [availableVariants objectAtIndex:0];
- }
- }
- messageStyle.activeVariant = activeVariant;
-
- NSDictionary *prefDict = [adium.preferenceController preferencesForGroup:preferenceGroup];
-
- //Update message style behavior: XXX move this somewhere not per-chat
- [messageStyle setShowUserIcons:[[prefDict objectForKey:KEY_WEBKIT_SHOW_USER_ICONS] boolValue]];
- [messageStyle setShowHeader:[[prefDict objectForKey:KEY_WEBKIT_SHOW_HEADER] boolValue]];
- [messageStyle setUseCustomNameFormat:[[prefDict objectForKey:KEY_WEBKIT_USE_NAME_FORMAT] boolValue]];
- [messageStyle setNameFormat:[[prefDict objectForKey:KEY_WEBKIT_NAME_FORMAT] intValue]];
- [messageStyle setDateFormat:[prefDict objectForKey:KEY_WEBKIT_TIME_STAMP_FORMAT]];
- [messageStyle setShowIncomingMessageColors:[[prefDict objectForKey:KEY_WEBKIT_SHOW_MESSAGE_COLORS] boolValue]];
- [messageStyle setShowIncomingMessageFonts:[[prefDict objectForKey:KEY_WEBKIT_SHOW_MESSAGE_FONTS] boolValue]];
-
- //Custom background image
- //Webkit wants to load these from disk, but we have it stuffed in a plist. So we'll write it out as an image
- //into the cache and have webkit fetch from there.
- NSString *cachePath = nil;
- if ([[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"UseCustomBackground" forStyle:activeStyle]
- group:preferenceGroup] boolValue]) {
- cachePath = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundCachePath" forStyle:activeStyle]
- group:preferenceGroup];
- if (!cachePath || ![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
- NSData *backgroundImage = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Background" forStyle:activeStyle]
- group:PREF_GROUP_WEBKIT_BACKGROUND_IMAGES];
-
- if (backgroundImage) {
- //Generate a unique cache ID for this image
- NSInteger uniqueID = [[adium.preferenceController preferenceForKey:@"BackgroundCacheUniqueID"
- group:preferenceGroup] integerValue] + 1;
- [adium.preferenceController setPreference:[NSNumber numberWithInteger:uniqueID]
- forKey:@"BackgroundCacheUniqueID"
- group:preferenceGroup];
-
- //Cache the image under that unique ID
- //Since we prefix the filename with TEMP, Adium will automatically clean it up on quit
- cachePath = [self _webKitBackgroundImagePathForUniqueID:uniqueID];
- [backgroundImage writeToFile:cachePath atomically:YES];
-
- //Remember where we cached it
- [adium.preferenceController setPreference:cachePath
- forKey:[plugin styleSpecificKey:@"BackgroundCachePath" forStyle:activeStyle]
- group:preferenceGroup];
- } else {
- cachePath = @""; //No custom image found
+ dispatch_sync(webViewUpdateQueue, ^{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ //Cleanup first
+ [messageStyle autorelease]; messageStyle = nil;
+ [activeStyle release]; activeStyle = nil;
+
+ //Load the message style
+ messageStyle = [[plugin currentMessageStyleForChat:chat] retain];
+ activeStyle = [[[messageStyle bundle] bundleIdentifier] retain];
+ preferenceGroup = [[plugin preferenceGroupForChat:chat] retain];
+
+ [webView setPreferencesIdentifier:[NSString stringWithFormat:@"%@-%@",
+ activeStyle, preferenceGroup]];
+
+ //Get the prefered variant (or the default if a prefered is not available)
+ NSString *activeVariant;
+ activeVariant = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Variant" forStyle:activeStyle]
+ group:preferenceGroup];
+ if (!activeVariant || ![[messageStyle availableVariants] containsObject:activeVariant])
+ activeVariant = [messageStyle defaultVariant];
+ if (!activeVariant || ![[messageStyle availableVariants] containsObject:activeVariant]) {
+ /* If the message style doesn't specify a default variant, choose the first one.
+ * Note: Old styles (styleVersion < 3) will always report a variant for defaultVariant.
+ */
+ NSArray *availableVariants = [messageStyle availableVariants];
+ if ([availableVariants count]) {
+ activeVariant = [availableVariants objectAtIndex:0];
}
}
+ messageStyle.activeVariant = activeVariant;
- [messageStyle setCustomBackgroundColor:[[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundColor" forStyle:activeStyle]
- group:preferenceGroup] representedColor]];
- } else {
- [messageStyle setCustomBackgroundColor:nil];
- }
-
- [messageStyle setCustomBackgroundPath:cachePath];
- [messageStyle setCustomBackgroundType:[[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundType" forStyle:activeStyle]
- group:preferenceGroup] intValue]];
-
- BOOL isBackgroundTransparent = [[self messageStyle] isBackgroundTransparent];
- [webView setTransparent:isBackgroundTransparent];
- NSWindow *win = [webView window];
- if(win)
- [win setOpaque:!isBackgroundTransparent];
-
- //Update webview font settings
- NSString *fontFamily = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"FontFamily" forStyle:activeStyle]
- group:preferenceGroup];
- [webView setFontFamily:(fontFamily ? fontFamily : [messageStyle defaultFontFamily])];
-
- NSNumber *fontSize = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"FontSize" forStyle:activeStyle]
- group:preferenceGroup];
- [[webView preferences] setDefaultFontSize:[(fontSize ? fontSize : [messageStyle defaultFontSize]) intValue]];
-
- NSNumber *minSize = [adium.preferenceController preferenceForKey:KEY_WEBKIT_MIN_FONT_SIZE
+ NSDictionary *prefDict = [adium.preferenceController preferencesForGroup:preferenceGroup];
+
+ //Update message style behavior: XXX move this somewhere not per-chat
+ [messageStyle setShowUserIcons:[[prefDict objectForKey:KEY_WEBKIT_SHOW_USER_ICONS] boolValue]];
+ [messageStyle setShowHeader:[[prefDict objectForKey:KEY_WEBKIT_SHOW_HEADER] boolValue]];
+ [messageStyle setUseCustomNameFormat:[[prefDict objectForKey:KEY_WEBKIT_USE_NAME_FORMAT] boolValue]];
+ [messageStyle setNameFormat:[[prefDict objectForKey:KEY_WEBKIT_NAME_FORMAT] intValue]];
+ [messageStyle setDateFormat:[prefDict objectForKey:KEY_WEBKIT_TIME_STAMP_FORMAT]];
+ [messageStyle setShowIncomingMessageColors:[[prefDict objectForKey:KEY_WEBKIT_SHOW_MESSAGE_COLORS] boolValue]];
+ [messageStyle setShowIncomingMessageFonts:[[prefDict objectForKey:KEY_WEBKIT_SHOW_MESSAGE_FONTS] boolValue]];
+
+ //Custom background image
+ //Webkit wants to load these from disk, but we have it stuffed in a plist. So we'll write it out as an image
+ //into the cache and have webkit fetch from there.
+ NSString *cachePath = nil;
+ if ([[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"UseCustomBackground" forStyle:activeStyle]
+ group:preferenceGroup] boolValue]) {
+ cachePath = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundCachePath" forStyle:activeStyle]
group:preferenceGroup];
- [[webView preferences] setMinimumFontSize:(minSize ? [minSize intValue] : 1)];
- [[webView preferences] setMinimumLogicalFontSize:(minSize ? [minSize intValue] : 1)];
-
- dispatch_async(dispatch_get_current_queue(), ^{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ if (!cachePath || ![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
+ NSData *backgroundImage = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"Background" forStyle:activeStyle]
+ group:PREF_GROUP_WEBKIT_BACKGROUND_IMAGES];
+
+ if (backgroundImage) {
+ //Generate a unique cache ID for this image
+ NSInteger uniqueID = [[adium.preferenceController preferenceForKey:@"BackgroundCacheUniqueID"
+ group:preferenceGroup] integerValue] + 1;
+ [adium.preferenceController setPreference:[NSNumber numberWithInteger:uniqueID]
+ forKey:@"BackgroundCacheUniqueID"
+ group:preferenceGroup];
+
+ //Cache the image under that unique ID
+ //Since we prefix the filename with TEMP, Adium will automatically clean it up on quit
+ cachePath = [self _webKitBackgroundImagePathForUniqueID:uniqueID];
+ [backgroundImage writeToFile:cachePath atomically:YES];
+
+ //Remember where we cached it
+ [adium.preferenceController setPreference:cachePath
+ forKey:[plugin styleSpecificKey:@"BackgroundCachePath" forStyle:activeStyle]
+ group:preferenceGroup];
+ } else {
+ cachePath = @""; //No custom image found
+ }
+ }
+
+ [messageStyle setCustomBackgroundColor:[[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundColor" forStyle:activeStyle]
+ group:preferenceGroup] representedColor]];
+ } else {
+ [messageStyle setCustomBackgroundColor:nil];
+ }
+
+ [messageStyle setCustomBackgroundPath:cachePath];
+ [messageStyle setCustomBackgroundType:[[adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"BackgroundType" forStyle:activeStyle]
+ group:preferenceGroup] intValue]];
+
+ BOOL isBackgroundTransparent = [[self messageStyle] isBackgroundTransparent];
+ [webView setTransparent:isBackgroundTransparent];
+ NSWindow *win = [webView window];
+ if(win)
+ [win setOpaque:!isBackgroundTransparent];
+
+ //Update webview font settings
+ NSString *fontFamily = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"FontFamily" forStyle:activeStyle]
+ group:preferenceGroup];
+ [webView setFontFamily:(fontFamily ? fontFamily : [messageStyle defaultFontFamily])];
+
+ NSNumber *fontSize = [adium.preferenceController preferenceForKey:[plugin styleSpecificKey:@"FontSize" forStyle:activeStyle]
+ group:preferenceGroup];
+ [[webView preferences] setDefaultFontSize:[(fontSize ? fontSize : [messageStyle defaultFontSize]) intValue]];
+
+ NSNumber *minSize = [adium.preferenceController preferenceForKey:KEY_WEBKIT_MIN_FONT_SIZE
+ group:preferenceGroup];
+ [[webView preferences] setMinimumFontSize:(minSize ? [minSize intValue] : 1)];
+ [[webView preferences] setMinimumLogicalFontSize:(minSize ? [minSize intValue] : 1)];
+
//Update our icons before doing any loading
[self sourceOrDestinationChanged:nil];
More information about the commits
mailing list