adium 2440:df64e5f551ef: Reload message style resources if the b...
commits at adium.im
commits at adium.im
Mon Jun 1 20:21:12 UTC 2009
details: http://hg.adium.im/adium/rev/df64e5f551ef
revision: 2440:df64e5f551ef
author: David Smith <catfish.man at gmail.com>
date: Mon Jun 01 13:20:48 2009 -0700
Reload message style resources if the bundle has been updated since the last time we loaded a style
diffs (297 lines):
diff -r dfea1a2fe3f2 -r df64e5f551ef Plugins/WebKit Message View/AIWebKitMessageViewPlugin.h
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.h Mon Jun 01 14:17:04 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.h Mon Jun 01 13:20:48 2009 -0700
@@ -115,6 +115,7 @@
NSMutableDictionary *styleDictionary;
AIWebkitMessageViewStyle *currentGroupStyle;
AIWebkitMessageViewStyle *currentRegularStyle;
+ NSDate *lastStyleLoadDate;
BOOL useRegularForGroupChat;
}
diff -r dfea1a2fe3f2 -r df64e5f551ef Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Mon Jun 01 14:17:04 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Mon Jun 01 13:20:48 2009 -0700
@@ -75,6 +75,7 @@
[preferences release]; preferences = nil;
[currentRegularStyle release]; currentRegularStyle = nil;
[currentGroupStyle release]; currentGroupStyle = nil;
+ [lastStyleLoadDate release]; lastStyleLoadDate = nil;
[super uninstallPlugin];
}
@@ -199,6 +200,16 @@
[*thisStyle retain];
}
+ NSDictionary *fileAttrs = [[NSFileManager defaultManager] fileAttributesAtPath:[[*thisStyle bundle] bundlePath]
+ traverseLink:YES];
+ NSDate *modDate = [fileAttrs objectForKey:NSFileModificationDate];
+ if (lastStyleLoadDate && [modDate timeIntervalSinceDate:lastStyleLoadDate] > 0) {
+ [currentGroupStyle reloadStyle];
+ [currentRegularStyle reloadStyle];
+ }
+ [lastStyleLoadDate release];
+ lastStyleLoadDate = [[NSDate date] retain];
+
return *thisStyle;
}
diff -r dfea1a2fe3f2 -r df64e5f551ef Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Mon Jun 01 14:17:04 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Mon Jun 01 13:20:48 2009 -0700
@@ -140,6 +140,11 @@
- (NSBundle *)bundle;
/*!
+ * @brief Reloads the content of the style, useful for style authors and updates
+ */
+- (void) reloadStyle;
+
+/*!
* Returns YES if this style is considered legacy
*
* Legacy/outdated styles may perform sub-optimally because they lack beneficial changes made in modern styles.
@@ -187,12 +192,12 @@
/*!
* @brief Style supports custom backgrounds
*/
-- (BOOL)allowsCustomBackground;
+ at property (readonly) BOOL allowsCustomBackground;
/*!
* @brief Style has a transparent background
*/
-- (BOOL)isBackgroundTransparent;
+ at property (readonly) BOOL isBackgroundTransparent;
/*!
@@ -209,27 +214,27 @@
/*!
* @brief Style has a header
*/
-- (BOOL)hasHeader;
+ at property (readonly) BOOL hasHeader;
/*!
* @brief Style has a topic
*/
-- (BOOL)hasTopic;
+ at property (readonly) BOOL hasTopic;
/*!
* @brief Style's user icon mask
*/
-- (NSImage *)userIconMask;
+ at property (readonly) NSImage *userIconMask;
/*!
* @brief Style supports user icons
*/
-- (BOOL)allowsUserIcons;
+ at property (readonly) BOOL allowsUserIcons;
/*!
* @brief Style supports display of text colors
*/
-- (BOOL)allowsColors;
+ at property (readonly) BOOL allowsColors;
//Behavior
/*!
diff -r dfea1a2fe3f2 -r df64e5f551ef Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Mon Jun 01 14:17:04 2009 -0400
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Mon Jun 01 13:20:48 2009 -0700
@@ -113,6 +113,7 @@
@interface AIWebkitMessageViewStyle ()
- (id)initWithBundle:(NSBundle *)inBundle;
- (void)_loadTemplates;
+- (void)releaseResources;
- (NSMutableString *)_escapeStringForPassingToScript:(NSMutableString *)inString;
- (NSString *)noVariantName;
- (NSString *)iconPathForFileTransfer:(ESFileTransfer *)inObject;
@@ -142,59 +143,62 @@
if ((self = [super init])) {
styleBundle = [inBundle retain];
stylePath = [[styleBundle resourcePath] retain];
-
- //Default behavior
- allowTextBackgrounds = YES;
-
- /* Our styles are versioned so we can change how they work without breaking compatibility.
- *
- * Version 0: Initial Webkit Version
- * Version 1: Template.html now handles all scroll-to-bottom functionality. It is no longer required to call the
- * scrollToBottom functions when inserting content.
- * Version 2: No significant changes
- * Version 3: main.css is no longer a separate style, it now serves as the base stylesheet and is imported by default.
- * The default variant is now a separate file in /variants like all other variants.
- * Template.html now includes appendMessageNoScroll() and appendNextMessageNoScroll() which behave
- * the same as appendMessage() and appendNextMessage() in Versions 1 and 2 but without scrolling.
- * Version 4: Template.html now includes replaceLastMessage()
- * Template.html now defines actionMessageUserName and actionMessageBody for display of /me (actions).
- * If the style provides a custom Template.html, these classes must be defined.
- * CSS can be used to customize the appearance of actions.
- * HTML filters in are now supported in Adium's content filter system; filters can assume Version 4 or later.
- */
- styleVersion = [[styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_VERSION] integerValue];
-
- //Pre-fetch our templates
- [self _loadTemplates];
-
- //Style flags
- allowsCustomBackground = ![[styleBundle objectForInfoDictionaryKey:@"DisableCustomBackground"] boolValue];
- transparentDefaultBackground = [[styleBundle objectForInfoDictionaryKey:@"DefaultBackgroundIsTransparent"] boolValue];
-
- combineConsecutive = ![[styleBundle objectForInfoDictionaryKey:@"DisableCombineConsecutive"] boolValue];
-
- NSNumber *tmpNum = [styleBundle objectForInfoDictionaryKey:@"ShowsUserIcons"];
- allowsUserIcons = (tmpNum ? [tmpNum boolValue] : YES);
-
- //User icon masking
- NSString *tmpName = [styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_USER_ICON_MASK];
- if (tmpName) userIconMask = [[NSImage alloc] initWithContentsOfFile:[stylePath stringByAppendingPathComponent:tmpName]];
-
- NSNumber *allowsColorsNumber = [styleBundle objectForInfoDictionaryKey:@"AllowTextColors"];
- allowsColors = (allowsColorsNumber ? [allowsColorsNumber boolValue] : YES);
+ [self reloadStyle];
}
return self;
}
+- (void) reloadStyle
+{
+ [self releaseResources];
+
+ //Default behavior
+ allowTextBackgrounds = YES;
+
+ /* Our styles are versioned so we can change how they work without breaking compatibility.
+ *
+ * Version 0: Initial Webkit Version
+ * Version 1: Template.html now handles all scroll-to-bottom functionality. It is no longer required to call the
+ * scrollToBottom functions when inserting content.
+ * Version 2: No significant changes
+ * Version 3: main.css is no longer a separate style, it now serves as the base stylesheet and is imported by default.
+ * The default variant is now a separate file in /variants like all other variants.
+ * Template.html now includes appendMessageNoScroll() and appendNextMessageNoScroll() which behave
+ * the same as appendMessage() and appendNextMessage() in Versions 1 and 2 but without scrolling.
+ * Version 4: Template.html now includes replaceLastMessage()
+ * Template.html now defines actionMessageUserName and actionMessageBody for display of /me (actions).
+ * If the style provides a custom Template.html, these classes must be defined.
+ * CSS can be used to customize the appearance of actions.
+ * HTML filters in are now supported in Adium's content filter system; filters can assume Version 4 or later.
+ */
+ styleVersion = [[styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_VERSION] integerValue];
+
+ //Pre-fetch our templates
+ [self _loadTemplates];
+
+ //Style flags
+ allowsCustomBackground = ![[styleBundle objectForInfoDictionaryKey:@"DisableCustomBackground"] boolValue];
+ transparentDefaultBackground = [[styleBundle objectForInfoDictionaryKey:@"DefaultBackgroundIsTransparent"] boolValue];
+
+ combineConsecutive = ![[styleBundle objectForInfoDictionaryKey:@"DisableCombineConsecutive"] boolValue];
+
+ NSNumber *tmpNum = [styleBundle objectForInfoDictionaryKey:@"ShowsUserIcons"];
+ allowsUserIcons = (tmpNum ? [tmpNum boolValue] : YES);
+
+ //User icon masking
+ NSString *tmpName = [styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_USER_ICON_MASK];
+ if (tmpName) userIconMask = [[NSImage alloc] initWithContentsOfFile:[stylePath stringByAppendingPathComponent:tmpName]];
+
+ NSNumber *allowsColorsNumber = [styleBundle objectForInfoDictionaryKey:@"AllowTextColors"];
+ allowsColors = (allowsColorsNumber ? [allowsColorsNumber boolValue] : YES);
+}
+
/*!
- * @brief Deallocate
+ * @brief release everything we loaded from the style bundle
*/
-- (void)dealloc
-{
- [styleBundle release];
- [stylePath release];
-
+- (void)releaseResources
+{
//Templates
[headerHTML release];
[footerHTML release];
@@ -211,13 +215,23 @@
[statusHTML release];
[fileTransferHTML release];
[topicHTML release];
-
- [timeStampFormatter release];
-
+
[customBackgroundPath release];
[customBackgroundColor release];
[userIconMask release];
+}
+
+/*!
+ * @brief Deallocate
+ */
+- (void)dealloc
+{
+ [styleBundle release];
+ [stylePath release];
+
+ [self releaseResources];
+ [timeStampFormatter release];
[statusIconPathCache release];
@@ -229,17 +243,14 @@
return styleBundle;
}
-
- (BOOL)isLegacy
{
return styleVersion < LEGACY_VERSION_THRESHOLD;
}
#pragma mark Settings
-- (BOOL)allowsCustomBackground
-{
- return allowsCustomBackground;
-}
+
+ at synthesize allowsCustomBackground, allowsUserIcons, allowsColors, userIconMask;
- (BOOL)isBackgroundTransparent
{
@@ -248,15 +259,6 @@
(customBackgroundColor && [customBackgroundColor alphaComponent] < 0.99));
}
-- (BOOL)allowsUserIcons
-{
- return allowsUserIcons;
-}
-
-- (BOOL)allowsColors;
-{
- return allowsColors;
-}
- (NSString *)defaultFontFamily
{
NSString *defaultFontFamily = [styleBundle objectForInfoDictionaryKey:KEY_WEBKIT_DEFAULT_FONT_FAMILY];
@@ -284,11 +286,6 @@
return topicHTML && [topicHTML length];
}
-- (NSImage *)userIconMask
-{
- return userIconMask;
-}
-
#pragma mark Behavior
- (void)setDateFormat:(NSString *)format
More information about the commits
mailing list