1/* OperationPrefs.m
2 *
3 * Copyright (C) 2004-2014 Free Software Foundation, Inc.
4 *
5 * Author: Enrico Sersale <enrico@imago.ro>
6 * Date: March 2004
7 *
8 * This file is part of the GNUstep Operation application
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
23 */
24
25#import <Foundation/Foundation.h>
26#import <AppKit/AppKit.h>
27#import <GNUstepBase/GNUstep.h>
28
29#import "OperationPrefs.h"
30
31
32static NSString *nibName = @"OperationPrefs";
33
34#define MOVEOP 0
35#define COPYOP 1
36#define LINKOP 2
37#define RECYCLEOP 3
38#define DUPLICATEOP 4
39#define DESTROYOP 5
40
41@implementation OperationPrefs
42
43- (void)dealloc
44{
45  RELEASE (prefbox);
46  [super dealloc];
47}
48
49- (id)init
50{
51  self = [super init];
52
53  if (self) {
54    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
55    NSArray *cells;
56    NSString *confirmString;
57    id butt;
58
59    if ([NSBundle loadNibNamed: nibName owner: self] == NO) {
60      NSLog(@"failed to load %@!", nibName);
61      DESTROY (self);
62      return self;
63    }
64
65    RETAIN (prefbox);
66    RELEASE (win);
67
68    statusItem = [tabView tabViewItemAtIndex: 0];
69    [statusItem setLabel: NSLocalizedString(@"Status Window", @"")];
70
71    confirmItem = [tabView tabViewItemAtIndex: 1];
72    [confirmItem setLabel: NSLocalizedString(@"Confirmation", @"")];
73
74    showstatus = (![defaults boolForKey: @"fopstatusnotshown"]);
75    [statChooseButt setState: (showstatus ? NSOnState : NSOffState)];
76
77    cells = [confMatrix cells];
78
79    butt = [cells objectAtIndex: MOVEOP];
80    confirmString = [NSWorkspaceMoveOperation stringByAppendingString: @"Confirm"];
81    [butt setState: !([defaults boolForKey: confirmString])];
82
83    butt = [cells objectAtIndex: COPYOP];
84    confirmString = [NSWorkspaceCopyOperation stringByAppendingString: @"Confirm"];
85    [butt setState: !([defaults boolForKey: confirmString])];
86
87    butt = [cells objectAtIndex: LINKOP];
88    confirmString = [NSWorkspaceLinkOperation stringByAppendingString: @"Confirm"];
89    [butt setState: !([defaults boolForKey: confirmString])];
90
91    butt = [cells objectAtIndex: RECYCLEOP];
92    confirmString = [NSWorkspaceRecycleOperation stringByAppendingString: @"Confirm"];
93    [butt setState: !([defaults boolForKey: confirmString])];
94
95    butt = [cells objectAtIndex: DUPLICATEOP];
96    confirmString = [NSWorkspaceDuplicateOperation stringByAppendingString: @"Confirm"];
97    [butt setState: !([defaults boolForKey: confirmString])];
98
99    butt = [cells objectAtIndex: DESTROYOP];
100    confirmString = [NSWorkspaceDestroyOperation stringByAppendingString: @"Confirm"];
101    [butt setState: !([defaults boolForKey: confirmString])];
102
103    /* Internationalization */
104    [win setTitle: NSLocalizedString(@"Operation Preferences", @"")];
105    [statusBox setTitle: NSLocalizedString(@"Status Window", @"")];
106    [statuslabel setStringValue: NSLocalizedString(@"Show status window", @"")];
107    [statusinfo1 setStringValue: NSLocalizedString(@"Check this option to show a status window", @"")];
108    [statusinfo2 setStringValue: NSLocalizedString(@"during the file operations", @"")];
109    [confirmBox setTitle: NSLocalizedString(@"Confirmation", @"")];
110    [[confMatrix cellAtRow:0 column:0] setTitle: NSLocalizedString(@"Move", @"")];
111    [[confMatrix cellAtRow:1 column:0] setTitle: NSLocalizedString(@"Copy", @"")];
112    [[confMatrix cellAtRow:2 column:0] setTitle: NSLocalizedString(@"Link", @"")];
113    [[confMatrix cellAtRow:3 column:0] setTitle: NSLocalizedString(@"Recycler", @"")];
114    [[confMatrix cellAtRow:4 column:0] setTitle: NSLocalizedString(@"Duplicate", @"")];
115    [[confMatrix cellAtRow:5 column:0] setTitle: NSLocalizedString(@"Destroy", @"")];
116    [labelinfo1 setStringValue: NSLocalizedString(@"Uncheck the buttons to allow automatic confirmation", @"")];
117    [labelinfo2 setStringValue: NSLocalizedString(@"of file operations", @"")];
118  }
119
120  return self;
121}
122
123- (NSView *)prefView
124{
125  return prefbox;
126}
127
128- (NSString *)prefName
129{
130  return NSLocalizedString(@"File Operations", @"");
131}
132
133- (void)setUnsetStatWin:(id)sender
134{
135  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
136  showstatus = ([sender state] == NSOnState) ? YES : NO;
137  [defaults setBool: !showstatus forKey: @"fopstatusnotshown"];
138  [defaults synchronize];
139}
140
141- (void)setUnsetFileOp:(id)sender
142{
143  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
144  NSArray *cells = [confMatrix cells];
145  NSString *confirmString;
146
147#define CHECK_CONFIRM(x, s) \
148confirmString = [s stringByAppendingString: @"Confirm"]; \
149[defaults setBool: (([[cells objectAtIndex: x] state] == NSOnState) ? NO : YES) \
150forKey: confirmString]
151
152  CHECK_CONFIRM (MOVEOP, NSWorkspaceMoveOperation);
153  CHECK_CONFIRM (COPYOP, NSWorkspaceCopyOperation);
154  CHECK_CONFIRM (LINKOP, NSWorkspaceLinkOperation);
155  CHECK_CONFIRM (RECYCLEOP, NSWorkspaceRecycleOperation);
156  CHECK_CONFIRM (RECYCLEOP, @"GWorkspaceRecycleOutOperation");
157  CHECK_CONFIRM (RECYCLEOP, @"GWorkspaceEmptyRecyclerOperation");
158  CHECK_CONFIRM (DUPLICATEOP, NSWorkspaceDuplicateOperation);
159  CHECK_CONFIRM (DESTROYOP, NSWorkspaceDestroyOperation);
160
161  [defaults synchronize];
162}
163
164@end
165