Subversion Repositories TruePreview

[/] [trunk/] [Source/] [TruePreviewPreferenceValueTransformer.m] - Blame information for rev 47

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jhriggs
/*
2 42 jhriggs
 * Copyright (c) 2009-2011, Jim Riggs, Christian Serving, L.L.C.
3 14 jhriggs
 * 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 "TruePreviewPreferenceValueTransformer.h"
33
 
34
@implementation TruePreviewPreferenceValueTransformer
35
 
36
#pragma mark NSValueTransformer class methods
37
 
38
+ (Class)transformedValueClass {
39 47 jhriggs
  TRUEPREVIEW_LOG();
40
 
41 14 jhriggs
  return [NSNumber class];
42
}
43
 
44
#pragma mark NSValueTransformer instance methods
45
 
46
- (id)transformedValue:(id)inValue {
47 47 jhriggs
  TRUEPREVIEW_LOG(@"%@", inValue);
48
 
49 14 jhriggs
  float theValue = [inValue floatValue];
50
 
51
  if ((theValue > 0) && (theValue <= TRUEPREVIEW_DELAY_MAX)) {
52
    return [NSNumber numberWithInt:1];
53
  }
54
  else if (
55
    (theValue == TRUEPREVIEW_DELAY_IMMEDIATE)
56
    || (theValue == TRUEPREVIEW_DELAY_DEFAULT)
57
    || (theValue == TRUEPREVIEW_DELAY_NEVER)
58
  ) {
59
    return [NSNumber numberWithInt:theValue];
60
  }
61
  else {
62
    return [NSNumber numberWithInt:TRUEPREVIEW_DELAY_DEFAULT];
63
  }
64
}
65
 
66
@end
67
 
68
@implementation TruePreviewPreferenceValueTransformerDelay
69
 
70
#pragma mark NSValueTransformer class methods
71
 
72
+ (Class)transformedValueClass {
73 47 jhriggs
  TRUEPREVIEW_LOG();
74
 
75 14 jhriggs
  return [NSNumber class];
76
}
77
 
78
#pragma mark NSValueTransformer instance methods
79
 
80
- (id)transformedValue:(id)inValue {
81 47 jhriggs
  TRUEPREVIEW_LOG(@"%@", inValue);
82
 
83 14 jhriggs
  float theValue = [inValue floatValue];
84
 
85
  if ((theValue <= 0) || (theValue > TRUEPREVIEW_DELAY_MAX)) {
86
    return nil;
87
  }
88
  else {
89
    return [NSNumber numberWithFloat:theValue];
90
  }
91
}
92
 
93
@end
94
 
95
@implementation TruePreviewPreferenceValueTransformerDelayEditIndicator
96
 
97
#pragma mark NSValueTransformer class methods
98
 
99
+ (Class)transformedValueClass {
100 47 jhriggs
  TRUEPREVIEW_LOG();
101
 
102 14 jhriggs
  return [NSNumber class];
103
}
104
 
105
#pragma mark NSValueTransformer instance methods
106
 
107
- (id)transformedValue:(id)inValue {
108 47 jhriggs
  TRUEPREVIEW_LOG(@"%@", inValue);
109
 
110 14 jhriggs
  float theValue = [inValue floatValue];
111
 
112
  return [NSNumber numberWithInt:((theValue > 0) && (theValue <= TRUEPREVIEW_DELAY_MAX))];
113
}
114
 
115
@end