File: PreferencesController.m

package info (click to toggle)
zipper.app 1.5-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 644 kB
  • sloc: objc: 3,829; makefile: 11
file content (382 lines) | stat: -rw-r--r-- 9,011 bytes parent folder | download | duplicates (3)
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*

  PreferencesController.m
  Zipper

  Copyright (C) 2012 Free Software Foundation, Inc

  Authors: Dirk Olmes <dirk@xanthippe.ping.de>
           Riccardo Mottola <rm@gnu.org>

  This application 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

 */

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#import "PreferencesController.h"
#import "Preferences.h"
#import "Archive.h"

#define TAG_TAR		1
#define TAG_UNZIP	2
#define TAG_RAR		3
#define TAG_LHA		4
#define TAG_LZX		5
#define TAG_SEVEN_ZIP	6
#define TAG_ZIP		7
#define TAG_GZIP	8
#define TAG_GUNZIP	9
#define TAG_BZIP2	10
#define TAG_BUNZIP2	11
#define TAG_UNARJ	12
#define TAG_UNACE	13
#define TAG_ZOO		14
#define TAG_XZ		15

@implementation PreferencesController : NSObject

- (id)init
{
  NSString *string;
  BOOL tarFlag;

  [super init];
  [NSBundle loadNibNamed: @"Preferences" owner: self];
    
  // tar
  string = [Preferences tarExecutable];
  if (!string)
    string = @"";
  [_tarTextField setStringValue:string];

  // unzip
  string = [Preferences unzipExecutable];
  if (!string)
    string = @"";
  [_unzipTextField setStringValue:string];

  // zip
  string = [Preferences zipExecutable];
  if (!string)
    string = @"";
  [_zipTextField setStringValue:string];

  // rar
  string = [Preferences rarExecutable];
  if (!string)
    string = @"";
  [_rarTextField setStringValue:string];

  // lha
  string = [Preferences lhaExecutable];
  if (!string)
    string = @"";
  [_lhaTextField setStringValue:string];

  // lzx
  string = [Preferences lzxExecutable];
  if (!string)
    string = @"";
  [_lzxTextField setStringValue:string];

  // 7z
  string = [Preferences sevenZipExecutable];
  if (!string)
    string = @"";
  [_sevenZipTextField setStringValue:string];

  // gzip 
  string = [Preferences gzipExecutable];
  if (!string)
    string = @"";
  [_gzipTextField setStringValue:string];

  // gunzip 
  string = [Preferences gunzipExecutable];
  if (!string)
    string = @"";
  [_gunzipTextField setStringValue:string];

  // bzip2 
  string = [Preferences bzip2Executable];
  if (!string)
    string = @"";
  [_bzip2TextField setStringValue:string];

  // bunzip2 
  string = [Preferences bunzip2Executable];
  if (!string)
    string = @"";
  [_bunzip2TextField setStringValue:string];

  // unarj 
  string = [Preferences unarjExecutable];
  if (!string)
    string = @"";
  [_unarjTextField setStringValue:string];

  // unace 
  string = [Preferences unaceExecutable];
  if (!string)
    string = @"";
  [_unaceTextField setStringValue:string];

  // zoo 
  string = [Preferences zooExecutable];
  if (!string)
    string = @"";
  [_zooTextField setStringValue:string];

  // xz 
  string = [Preferences xzExecutable];
  if (!string)
    string = @"";
  [_xzTextField setStringValue:string];

  // bsd tar checkbox
  tarFlag = [Preferences isBsdTar];
  [_bsdTarButton setState:tarFlag];

  // default open app text field
  string = [[Preferences defaultOpenApp] lastPathComponent];
  if (!string)
    string = @"";
  [_defaultOpenApp setStringValue:string];

  return self;
}

- (void)awakeFromNib
{
  NSClipView *cView;

  NSLog(@"fix scroll");
  cView = [scrollView contentView];
  [cView scrollToPoint: NSMakePoint(0.0, NSMaxY([[scrollView documentView] frame])-NSHeight([cView bounds]))];
  [scrollView reflectScrolledClipView: cView];
}

- (void)dealloc
{
        [_panel release];
        [_archiveClass release];
        [super dealloc];
}

/**
 * runs the Preferences Panel in a modal event loop
 */
- (void)showPreferencesPanel
{  
  [NSApp runModalForWindow:_panel];
  // control flow returns to the panel ... until 'ok' or 'cancel' is pressed

  [_panel close];
}

-(void)windowWillClose:(NSNotification *)aNotification
{
  [NSApp stopModal];
}

- (IBAction)okPressed:(id)sender
{
	NSString *string;

	NS_DURING
		string = [_tarTextField stringValue];
		[Preferences setTarExecutable:string];

		string = [_unzipTextField stringValue];
		[Preferences setUnzipExecutable:string];

		string = [_zipTextField stringValue];
		[Preferences setZipExecutable:string];
		
		string = [_rarTextField stringValue];
		[Preferences setRarExecutable:string];
		
		string = [_lhaTextField stringValue];
		[Preferences setLhaExecutable:string];

		string = [_lzxTextField stringValue];
		[Preferences setLzxExecutable:string];

		string = [_sevenZipTextField stringValue];
		[Preferences setSevenZipExecutable:string];

		string = [_gzipTextField stringValue];
		[Preferences setGzipExecutable:string];

		string = [_gunzipTextField stringValue];
		[Preferences setGunzipExecutable:string];

		string = [_bzip2TextField stringValue];
		[Preferences setBzip2Executable:string];

		string = [_bunzip2TextField stringValue];
		[Preferences setBunzip2Executable:string];

		string = [_unarjTextField stringValue];
		[Preferences setUnarjExecutable:string];

		string = [_unaceTextField stringValue];
		[Preferences setUnaceExecutable:string];

		string = [_zooTextField stringValue];
		[Preferences setZooExecutable:string];

		string = [_xzTextField stringValue];
		[Preferences setXzExecutable:string];

		[Preferences setIsBsdTar:[_bsdTarButton state]];
		[Preferences save];

		[_panel performClose:self];
	NS_HANDLER
		NSRunAlertPanel(@"Error in Preferences", [localException reason], nil, nil, nil);
	NS_ENDHANDLER
}

- (IBAction)cancelPressed:(id)sender
{
  [_panel performClose:self];
}

- (IBAction)findExecutable:(id)sender
{
	NSOpenPanel *openPanel;
	int rc;
				
	openPanel = [NSOpenPanel openPanel];
	[openPanel setTitle:@"Find executable"];
	[openPanel setCanChooseFiles:YES];
	[openPanel setCanChooseDirectories:NO];

	rc = [openPanel runModalForDirectory:@"/" file:nil types:nil];
	if (rc == NSOKButton)
	{
		NSString *path = [openPanel filename];
		
		NS_DURING
			switch ([sender tag])
			{
				case TAG_TAR:
					[_tarTextField setStringValue:path];
					[Preferences setTarExecutable:path];
					break;
					
				case TAG_UNZIP:
					[_unzipTextField setStringValue:path];
					[Preferences setUnzipExecutable:path];
					break;

				case TAG_ZIP:
					[_zipTextField setStringValue:path];
					[Preferences setZipExecutable:path];
					break;
				
				case TAG_RAR:
					[_rarTextField setStringValue:path];
					[Preferences setRarExecutable:path];
					break;
					
				case TAG_LHA:
					[_lhaTextField setStringValue:path];
					[Preferences setLhaExecutable:path];
					break;

				case TAG_LZX:
					[_lzxTextField setStringValue:path];
					[Preferences setLzxExecutable:path];
					break;

				case TAG_SEVEN_ZIP:
					[_sevenZipTextField setStringValue:path];
					[Preferences setSevenZipExecutable:path];
					break;
				
				case TAG_GZIP:
					[_gzipTextField setStringValue:path];
					[Preferences setGzipExecutable:path];
					break;
				
				case TAG_GUNZIP:
					[_gunzipTextField setStringValue:path];
					[Preferences setGunzipExecutable:path];
					break;
				
				case TAG_BZIP2:
					[_bzip2TextField setStringValue:path];
					[Preferences setBzip2Executable:path];
					break;
				
				case TAG_BUNZIP2:
					[_bunzip2TextField setStringValue:path];
					[Preferences setBunzip2Executable:path];
					break;
				
				case TAG_UNARJ:
					[_unarjTextField setStringValue:path];
					[Preferences setUnarjExecutable:path];
					break;
				
				case TAG_UNACE:
					[_unaceTextField setStringValue:path];
					[Preferences setUnaceExecutable:path];
					break;
				
				case TAG_ZOO:
					[_zooTextField setStringValue:path];
					[Preferences setZooExecutable:path];
					break;
				
				case TAG_XZ:
					[_xzTextField setStringValue:path];
					[Preferences setXzExecutable:path];
					break;
				
				default:
					[NSException raise:NSInvalidArgumentException 
						format:@"invalid tag of find button"];
			}
		NS_HANDLER
			NSRunAlertPanel(@"Error in Preferences", [localException reason], nil, nil, nil);
		NS_ENDHANDLER
	}
}

- (IBAction)findDefaultOpenApp:(id)sender
{
	NSOpenPanel *openPanel;
	NSString *gnustepSystemApps;
	int rc;
				
	gnustepSystemApps = [NSSearchPathForDirectoriesInDomains(NSApplicationDirectory,
				NSSystemDomainMask, YES) objectAtIndex:0];
	
	openPanel = [NSOpenPanel openPanel];
	[openPanel setTitle:@"Find default open app"];
	[openPanel setTreatsFilePackagesAsDirectories:YES];
	[openPanel setCanChooseFiles:NO];
	[openPanel setCanChooseDirectories:YES];
	
	rc = [openPanel runModalForDirectory:gnustepSystemApps file:nil types:nil];
	if (rc == NSOKButton)
	{
		[_defaultOpenApp setStringValue:[[openPanel filename] lastPathComponent]];
		[Preferences setDefaultOpenApp:[openPanel filename]];
	}	
}

@end