Subversion Repositories TruePreview

[/] [trunk/] [Source/] [TruePreview.m] - Blame information for rev 1

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 jhriggs
/*
2
 * Copyright (c) 2009, Jim Riggs, Christian Serving, L.L.C.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are
7
 * met:
8
 *     * Redistributions of source code must retain the above copyright
9
 *       notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above
11
 *       copyright notice, this list of conditions and the following
12
 *       disclaimer in the documentation and/or other materials provided
13
 *       with the distribution.
14
 *     * Neither the name of Christian Serving, L.L.C. nor the names of
15
 *       its contributors may be used to endorse or promote products
16
 *       derived from this software without specific prior written
17
 *       permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 */
31
 
32
#import "TruePreview.h"
33
 
34
@implementation TruePreview
35
 
36
#pragma mark Class initialization
37
 
38
+ (void)initialize {
39
  [TruePreview registerBundle];
40
 
41
  // do our swizzles
42
  [NSPreferences
43
    truePreviewSwizzleMethod:@selector(sharedPreferences)
44
    withMethod:@selector(truePreviewSharedPreferences)
45
    isClassMethod:YES
46
  ];
47
  [LibraryMessage
48
    truePreviewSwizzleMethod:@selector(markAsViewed)
49
    withMethod:@selector(truePreviewMarkAsViewed)
50
    isClassMethod:NO
51
  ];
52
  [TableViewManager
53
    truePreviewSwizzleMethod:@selector(setCurrentDisplayedMessage:)
54
    withMethod:@selector(truePreviewSetCurrentDisplayedMessage:)
55
    isClassMethod:NO
56
  ];
57
 
58
  [[NSUserDefaults standardUserDefaults]
59
    registerDefaults:[NSDictionary
60
      dictionaryWithObject:[NSNumber numberWithInt:0] forKey:@"TruePreviewDelay"
61
    ]
62
  ];
63
 
64
  NSLog(
65
    @"Loaded TruePreview plugin %@",
66
    [[NSBundle bundleForClass:[TruePreview class]] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]
67
  );
68
}
69
 
70
#pragma mark MVMailBundle class methods
71
 
72
+ (BOOL)hasPreferencesPanel {
73
  return YES;
74
}
75
 
76
+ (NSString*)preferencesOwnerClassName {
77
  return NSStringFromClass([TruePreviewPreferencesModule class]);
78
}
79
 
80
+ (NSString*)preferencesPanelName {
81
  return @"TruePreview";
82
}
83
 
84
@end
85
 
86
@implementation NSObject (TruePreviewObject)
87
 
88
#pragma mark Class methods
89
 
90
+ (void)truePreviewSwizzleMethod:(SEL)inOriginalSelector withMethod:(SEL)inReplacementSelector isClassMethod:(BOOL)inIsClassMethod {
91
  Method theOriginalMethod = (!inIsClassMethod
92
    ? class_getInstanceMethod([self class], inOriginalSelector)
93
    : class_getClassMethod([self class], inOriginalSelector)
94
  );
95
  Method theReplacementMethod = (!inIsClassMethod
96
    ? class_getInstanceMethod([self class], inReplacementSelector)
97
    : class_getClassMethod([self class], inReplacementSelector)
98
  );
99
 
100
#if __OBJC2__
101
  method_exchangeImplementations(theOriginalMethod, theReplacementMethod);
102
#else
103
  char* theOriginalTypes = theOriginalMethod->method_types;
104
 
105
  theOriginalMethod->method_types = theReplacementMethod->method_types;
106
  theReplacementMethod->method_types = theOriginalTypes;
107
 
108
  IMP theOriginalImp = theOriginalMethod->method_imp;
109
 
110
  theOriginalMethod->method_imp = theReplacementMethod->method_imp;
111
  theReplacementMethod->method_imp = theOriginalImp;
112
#endif
113
}
114
 
115
@end