adium-1.4 3110:0e061cd60338: Improved the upgrade path for the n...
commits at adium.im
commits at adium.im
Thu Oct 21 00:40:33 UTC 2010
details: http://hg.adium.im/adium-1.4/rev/0e061cd60338
revision: 3110:0e061cd60338
author: Evan Schoenberg
date: Wed Oct 20 19:40:27 2010 -0500
Improved the upgrade path for the new webkit message styles and style identifiers to be nondestructive; we now carry the users previous style-specific preferences with us into Adium 1.4 rather than ignoring them.
diffs (132 lines):
diff -r fe763b8f8008 -r 0e061cd60338 Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Wed Oct 20 16:41:02 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewPlugin.m Wed Oct 20 19:40:27 2010 -0500
@@ -31,6 +31,7 @@
@interface AIWebKitMessageViewPlugin ()
- (void) resetStylesForType:(AIWebkitStyleType)styleType;
- (void)clearHardcodedBuiltInStylePaths;
+- (void)performAdium14PreferenceUpdates;
@end
@implementation AIWebKitMessageViewPlugin
@@ -42,8 +43,15 @@
{
styleDictionary = nil;
[adium createResourcePathForName:MESSAGE_STYLES_SUBFOLDER_OF_APP_SUPPORT];
+
+ /* If this isn't done, Bad Things happen, so check it each launch (cheap!) in case the user reverted to a
+ * pre-Adium 1.4 version. This check can be removed ~Adium 1.6.
+ */
[self clearHardcodedBuiltInStylePaths];
+ [self performAdium14PreferenceUpdates];
+
+
//Setup our preferences
[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:WEBKIT_DEFAULT_PREFS forClass:[self class]]
forGroup:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
@@ -138,32 +146,6 @@
NSDictionary *styles = [self availableMessageStyles];
NSBundle *defaultMessageStyleBundle = nil;
- if ([identifier isEqualToString:@"com.adiumx.eclipse.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Gone Dark.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.gonedark.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Gone Dark.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.minimal.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.minimal_mod.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.minimal_2.0.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.minimal_mod.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.minimal_mod.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.minimal_mod.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.mockie.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Mockie.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.renkooNaked.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Renkoo.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.renkoo.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Renkoo.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.smooth.operator.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Smooth Operator.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.plastic.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Stockholm.style"];
- } else if ([identifier isEqualToString:@"com.adiumx.stockholm.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.Stockholm.style"];
- } else if ([identifier isEqualToString:@"mathuaerknedam.yMous.style"]) {
- defaultMessageStyleBundle = [styles objectForKey:@"im.adium.yMous.style"];
- }
-
if (!defaultMessageStyleBundle) {
defaultMessageStyleBundle = [styles objectForKey:WEBKIT_DEFAULT_STYLE];
}
@@ -306,4 +288,71 @@
[self resetStylesForType:AIWebkitGroupChat];
}
+- (void)performAdium14PreferenceUpdates
+{
+ if (![[adium.preferenceController preferenceForKey:@"Adium 1.4:Updated Preferences"
+ group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY] boolValue]) {
+ NSDictionary *dict = [adium.preferenceController preferencesForGroup:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
+ NSMutableDictionary *newDict = [dict mutableCopy];
+ NSMutableSet *keysToRemove = [NSMutableSet set];
+
+ NSDictionary *conversionDict =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ /* complete style changes */
+ @"im.adium.Gone Dark.style", @"com.adiumx.eclipse.style",
+ @"im.adium.Stockholm.style", @"com.adiumx.plastic.style",
+ @"im.adium.minimal_mod.style", @"com.adiumx.minimal_2.0.style",
+ @"im.adium.Renkoo.style", @"com.adiumx.renkooNaked.style",
+ @"im.adium.minimal_mod.style", @"com.adiumx.minimal.style",
+
+ /* bundle identifier changes */
+ @"im.adium.Gone Dark.style", @"com.adiumx.gonedark.style",
+ @"im.adium.minimal_mod.style", @"com.adiumx.minimal_mod.style",
+ @"im.adium.Mockie.style", @"com.adiumx.mockie.style",
+ @"im.adium.Renkoo.style", @"com.adiumx.renkoo.style",
+ @"im.adium.Smooth Operator.style", @"com.adiumx.smooth.operator.style",
+ @"im.adium.Stockholm.style", @"com.adiumx.stockholm.style",
+ @"im.adium.yMous.style", @"mathuaerknedam.yMous.style",
+ nil];
+
+ /* Upgrade the style ID itself (that is, the style that Adium will be displaying) if it changed */
+ NSString *upgradedStyleID = [conversionDict objectForKey:[dict objectForKey:KEY_WEBKIT_STYLE]];
+ if (upgradedStyleID)
+ [newDict setObject:upgradedStyleID
+ forKey:KEY_WEBKIT_STYLE];
+
+ /* Now update style-specific preferences, whose keys are prefixed with style names, as needed */
+ for (NSString *key in [dict keyEnumerator]) {
+ /* For each changed bundle, check each key */
+ for (NSString *oldBundleID in [conversionDict keyEnumerator]) {
+ if ([key hasPrefix:oldBundleID]) {
+ NSString *newBundleID = [conversionDict objectForKey:oldBundleID];
+ NSString *newKey = [newBundleID stringByAppendingString:[key substringFromIndex:oldBundleID.length]];
+
+ /* Store with the new bundle ID in the key */
+ [newDict setObject:[dict objectForKey:key]
+ forKey:newKey];
+
+ /* Remove the obsolete preference; we'll want it not in the newDict but also need to manually
+ * remove it when we're done, since AIPreferenceController's setPreferences:inGroup: is nondestructive. */
+ [newDict removeObjectForKey:key];
+ [keysToRemove addObject:key];
+ }
+ }
+ }
+
+ [adium.preferenceController setPreferences:newDict
+ inGroup:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
+ for (NSString *key in keysToRemove) {
+ [adium.preferenceController setPreference:nil
+ forKey:key
+ group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
+ }
+
+ [adium.preferenceController setPreference:[NSNumber numberWithBool:YES]
+ forKey:@"Adium 1.4:Updated Preferences"
+ group:PREF_GROUP_WEBKIT_REGULAR_MESSAGE_DISPLAY];
+ }
+}
+
@end
More information about the commits
mailing list