1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
//
// Lynkeos
// $Id$
//
// Created by Jean-Etienne LAMIAUD on Wed Sep 24 2008.
// Copyright (c) 2008-2023. Jean-Etienne LAMIAUD
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "DcrawReaderPrefs.h"
NSString * const K_TMPDIR_KEY = @"RAW files conversion folder";
NSString * const K_MANUALWB_KEY = @"RAW manual white balance";
NSString * const K_RED_KEY = @"RAW red weight";
NSString * const K_GREEN1_KEY = @"RAW first green weight";
NSString * const K_BLUE_KEY = @"RAW blue weigh";
NSString * const K_GREEN2_KEY = @"RAW second green weigh";
NSString * const K_LEVELS_KEY = @"RAW manual levels";
NSString * const K_DARK_KEY = @"RAW dark level";
NSString * const K_SATURATION_KEY = @"RAW saturation level";
NSString * const K_ROTATION_KEY = @"RAW image rotation";
//! DcrawReaderPrefs singleton instance
static DcrawReaderPrefs *dcrawReaderPrefsInstance = nil;
/*!
* @abstract Private methods of DcrawReaderPrefs
*/
@interface DcrawReaderPrefs(Private)
//! Set the preferences to their factory defaults
- (void) initPrefs;
//! Read the preferences user values
- (void) readPrefs;
//! Update the panel fields to their current values
- (void) updatePanel;
@end
@implementation DcrawReaderPrefs(Private)
- (void) initPrefs
{
// Set the factory defaults
_tmpDir = nil;
_manualWB = NO;
_autoRotation = YES;
_red = 1.0;
_green1 = 1.0;
_blue = 1.0;
_green2 = 1.0;
_dark = -HUGE_VAL;
_saturation = HUGE_VAL;
}
- (void) readPrefs
{
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
NSFileManager *fileMgr = [NSFileManager defaultManager];
BOOL isDir;
_tmpDir = [user stringForKey:K_TMPDIR_KEY];
if ( _tmpDir != nil &&
(![fileMgr fileExistsAtPath:[_tmpDir stringByExpandingTildeInPath]
isDirectory:&isDir]
|| !isDir ) )
// Bad path
_tmpDir = nil;
if ( [user objectForKey:K_MANUALWB_KEY] != nil )
_manualWB = [user boolForKey:K_MANUALWB_KEY];
if ( [user objectForKey:K_ROTATION_KEY] != nil )
_autoRotation = [user boolForKey:K_ROTATION_KEY];
getNumericPref(&_red, K_RED_KEY, 0.0, 10.0);
getNumericPref(&_green1, K_GREEN1_KEY, 0.0, 10.0);
getNumericPref(&_blue, K_BLUE_KEY, 0.0, 10.0);
getNumericPref(&_green2, K_GREEN2_KEY, 0.0, 10.0);
_manualLevels = [user boolForKey:K_LEVELS_KEY];
getNumericPref(&_dark, K_DARK_KEY, 0.0, 65536.0);
getNumericPref(&_saturation, K_SATURATION_KEY, 0.0, 65536.0);
}
- (void) updatePanel
{
if ( _tmpDir != nil )
[_tmpDirText setStringValue:_tmpDir];
else
[_tmpDirText setStringValue:@""];
[_manualWbButton setState:(_manualWB ? NSOnState : NSOffState)];
[_autoRotationButton setState:(_autoRotation ? NSOnState : NSOffState)];
[_redText setDoubleValue:_red];
[_green1Text setDoubleValue:_green1];
[_blueText setDoubleValue:_blue];
[_green2Text setDoubleValue:_green2];
[_manualLevelsButton setState:(_manualLevels ? NSOnState : NSOffState)];
[_darkText setDoubleValue:_dark];
[_saturationText setDoubleValue:_saturation];
[_redText setEnabled:_manualWB];
[_green1Text setEnabled:_manualWB];
[_blueText setEnabled:_manualWB];
[_green2Text setEnabled:_manualWB];
[_darkText setEnabled:_manualLevels];
[_saturationText setEnabled:_manualLevels];
}
@end
@implementation DcrawReaderPrefs
+ (void) getPreferenceTitle:(NSString**)title
icon:(NSImage**)icon
tip:(NSString**)tip
{
#if !GNUSTEP
NSBundle *myBundle = [NSBundle bundleWithIdentifier:
@"net.sourceforge.lynkeos.plugin.RAW"];
*icon = [[[NSImage alloc] initWithContentsOfFile:
[myBundle pathForImageResource:@"Dcraw"]] autorelease];
#else
*icon = [NSImage imageNamed:@"Dcraw"];
#endif
*title = @"RAW";
*tip = nil;
}
+ (id <LynkeosPreferences>) getPreferenceInstance
{
if ( dcrawReaderPrefsInstance == nil )
[[self alloc] init];
return( dcrawReaderPrefsInstance );
}
- (id) init
{
NSAssert( dcrawReaderPrefsInstance == nil,
@"More than one creation of DcrawReaderPrefs" );
if ( (self = [super init]) != nil )
{
[self initPrefs];
[[NSBundle bundleForClass:[self class]] loadNibNamed:@"DcrawReaderPrefs" owner:self topLevelObjects:&_nibObjects];
[_nibObjects retain];
// Update with database value, if any
[self readPrefs];
// And rewrite them to ensure correct values
[self savePreferences:[NSUserDefaults standardUserDefaults]];
// Finally initialize the GUI
[self updatePanel];
dcrawReaderPrefsInstance = self;
}
return( self );
}
- (void) dealloc
{
[_nibObjects release];
[super dealloc];
}
- (NSView*) getPreferencesView
{
return( _prefsView );
}
- (void) savePreferences:(NSUserDefaults*)prefs
{
[prefs setObject:_tmpDir forKey:K_TMPDIR_KEY];
[prefs setBool:_manualWB forKey:K_MANUALWB_KEY];
[prefs setBool:_autoRotation forKey:K_ROTATION_KEY];
[prefs setFloat:_red forKey:K_RED_KEY];
[prefs setFloat:_green1 forKey:K_GREEN1_KEY];
[prefs setFloat:_blue forKey:K_BLUE_KEY];
[prefs setFloat:_green2 forKey:K_GREEN2_KEY];
[prefs setBool:_manualLevels forKey:K_LEVELS_KEY];
[prefs setFloat:_dark forKey:K_DARK_KEY];
[prefs setFloat:_saturation forKey:K_SATURATION_KEY];
}
- (void) revertPreferences
{
[self readPrefs];
[self updatePanel];
}
- (void) resetPreferences:(NSUserDefaults*)prefs
{
[self initPrefs];
[self savePreferences:prefs];
[self updatePanel];
}
- (IBAction)changeTmpDir:(id)sender
{
BOOL isDir;
if ( _tmpDir != nil )
[_tmpDir release];
_tmpDir = [sender stringValue];
if ( [_tmpDir length] <= 0
|| ![[NSFileManager defaultManager] fileExistsAtPath:
[_tmpDir stringByExpandingTildeInPath]
isDirectory:&isDir]
|| !isDir )
{
// if ( [_tmpDir length] > 0 )
// Bad path
// SysBeep(1);
_tmpDir = nil;
[sender setStringValue:@""];
}
else
[_tmpDir retain];
}
- (IBAction)changeManualWB:(id)sender
{
_manualWB = ([sender state] == NSOnState);
[self updatePanel];
}
- (IBAction)changeAutoRotation:(id)sender
{
_autoRotation = ([sender state] == NSOnState);
[self updatePanel];
}
- (IBAction)changeRed:(id)sender
{
_red = [sender doubleValue];
}
- (IBAction)changeGreen1:(id)sender
{
_green1 = [sender doubleValue];
}
- (IBAction)changeBlue:(id)sender
{
_blue = [sender doubleValue];
}
- (IBAction)changeGreen2:(id)sender
{
_green2 = [sender doubleValue];
}
- (IBAction)changeManualLevels:(id)sender
{
_manualLevels = ([sender state] == NSOnState);
[self updatePanel];
}
- (IBAction)changeDark:(id)sender
{
_dark = [sender doubleValue];
}
- (IBAction)changeSaturation:(id)sender
{
_saturation = [sender doubleValue];
}
@end
|