-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCSVPreferencesController.m
862 lines (730 loc) · 26.5 KB
/
CSVPreferencesController.m
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
//
// CSVPreferencesController.m
// CSV Touch
//
// Created by Simon Wigzell on 14/07/2008.
// Copyright 2008 Ozymandias. All rights reserved.
//
#import "CSVPreferencesController.h"
#import "OzymandiasAdditions.h"
@implementation CSVPreferencesController
#define PREFS_ENCODING @"encoding"
#define PREFS_ITEMS_LIST_FONT_SIZE @"itemsListFontSize"
#define PREFS_DETAILS_FONT_SIZE @"detailsFontSize"
#define PREFS_DELIMITER @"delimiter"
#define PREFS_SORTING_MASK @"sortingMask"
#define PREFS_USE_GROUPING_FOR_ITEMS @"useGroupingForItems"
#define PREFS_GROUP_NUMBERS @"groupNumbers"
#define PREFS_USE_MONOSPACED_FONT @"useMonospacedFont"
#define PREFS_FIXED_WIDTHS_ALTERNATIVE @"fixedWidthAlternative"
#define PREFS_KEEP_QUOTES @"keepQuotes"
#define PREFS_USE_CORRECT_PARSING @"useCorrectParsing"
#define PREFS_SHOULD_SORT @"shouldShort"
#define PREFS_USE_CORRECT_SORTING @"useCorrectSorting"
#define PREFS_SHOW_INLINE_IMAGES @"showInlineImages"
#define PREFS_NUMBER_SENSITIVE_SORTING @"numberSensitiveSorting"
#define PREFS_CASE_SENSITIVE_SORTING @"caseSensitiveSorting"
#define PREFS_LITERAL_SORTING @"literalSorting"
#define PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING @"clearSearchWhenQuickSelecting"
#define PREFS_HAS_SHOWN_HOW_TO @"hasShownHowTo"
#define PREFS_HIDE_ADDRESS @"hideAddress"
#define PREFS_LAST_DOWNLOAD @"lastDownload"
#define PREFS_BLANK_WORD_SEPARATOR @"blankWordSeparator"
#define LAST_USED_LIST_URL @"lastUsedListURL"
#define NEW_FILE_URL @"newFileURL"
#define PREFS_DETAILS_VIEW @"detailsView"
#define PREFS_SHOW_DELETED_COLUMNS @"showDeletedColumns"
#define PREFS_HIDE_EMPTY_COLUMNS @"showEmptyColumns"
#define PREFS_USE_AUTOMATED_DOWNLOAD @"useAutomatedDownload"
#define PREFS_CONFIGURED_DOWNLOAD_TIME @"configuredDownloadTime"
#define PREFS_MULTILINE_ITEM_CELLS @"multilineItemCells"
#define PREFS_REVERSE_ITEM_SORTING @"reverseItemSorting"
#define PREFS_SYNCHRONIZE_DOWNLOADED_FILES @"synchronizeDownloadedFiles"
#define PREFS_HAS_SHOWN_40_NOTES @"40NotesShown"
#define PREFS_HAS_SHOWN_42_RESIZING_NOTE @"42NotesShown"
#define NUMBER_OF_STARTS @"NUMBER_OF_STARTS"
// Since this value will be used really frequently, we cahce it for quick return
static BOOL _cachedReverseSorting;
NSUInteger sortingMask;
+ (void) applicationDidFinishLaunching
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Clean out old settings
[defaults removeObjectForKey:@"aboutID"];
[defaults removeObjectForKey:@"dataID"];
[defaults removeObjectForKey:@"sortingID"];
[defaults removeObjectForKey:@"appearanceID"];
[defaults removeObjectForKey:@"currentPrefsControllerStack"];
[defaults removeObjectForKey:@"maxNumberLiveFilter"];
[defaults removeObjectForKey:@"maxNumberOfItemsToSort"];
[defaults removeObjectForKey:@"searchStringsForFiles"];
[defaults removeObjectForKey:@"predefinedHiddenColumns"];
[defaults removeObjectForKey:@"itemPositionsForFiles"];
[defaults removeObjectForKey:@"useDetailsSwipe"];
[defaults removeObjectForKey:@"useSwipeAnimation"];
[defaults removeObjectForKey:@"useDetailsNavigation"];
[defaults removeObjectForKey:@"alignHtml"];
[defaults removeObjectForKey:@"tableViewSize"];
[defaults removeObjectForKey:@"detailsTableViewSize"];
[defaults removeObjectForKey:@"showDetailsToolbar"];
[defaults removeObjectForKey:@"confirmLink"];
[defaults removeObjectForKey:@"enablePhoneLinks"];
[defaults removeObjectForKey:@"showDebugInfo"];
[defaults removeObjectForKey:@"simpleMode"];
[defaults removeObjectForKey:@"safeStart"];
[defaults removeObjectForKey:@"maxSafeBackgroundMinutes"];
[defaults removeObjectForKey:@"usePassword"];
[defaults removeObjectForKey:@"useFixedWidth"];
[defaults removeObjectForKey:@"definedFixedWidths"];
[defaults removeObjectForKey:@"hasBeenUpgradedToCustomExtension"];
if( [defaults objectForKey:@"smartDelimiter"]){
[defaults removeObjectForKey:@"smartDelimiter"];
[self setDelimiter:nil];
}
// Setup sortingMask
[self updateSortingMask];
// Fix quick cache
[self updateFastCache];
[self resetDefaultsHaveChanges];
// Up the number of starts
[[NSUserDefaults standardUserDefaults] setInteger:[[NSUserDefaults standardUserDefaults] integerForKey:NUMBER_OF_STARTS]+1 forKey:NUMBER_OF_STARTS];
}
+ (void) setDelimiter:(NSString *)delimiter
{
if( delimiter == nil ){
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PREFS_DELIMITER];
}
else{
[[NSUserDefaults standardUserDefaults] setObject:delimiter forKey:PREFS_DELIMITER];
}
}
+ (NSString *) delimiter
{
return [[NSUserDefaults standardUserDefaults] stringForKey:PREFS_DELIMITER];
}
+ (BOOL) smartDelimiter
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_DELIMITER];
return obj == nil || [obj isEqualToString:@""];
}
+ (void) setStringEncoding:(NSStringEncoding)encoding
{
[[NSUserDefaults standardUserDefaults] setInteger:encoding forKey:PREFS_ENCODING];
}
+ (NSStringEncoding) encoding
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_ENCODING];
if( obj )
return [obj intValue];
else
return NSISOLatin1StringEncoding;
}
#define MAX_FONT_SIZE 160
#define MIN_FONT_SIZE 1
#define STANDARD_ITEMS_LIST_FONT_SIZE 14
#define STANDARD_DETAILS_VIEW_FONT_SIZE 36
+ (void) setItemsListFontSize:(NSInteger)size
{
if( size < MIN_FONT_SIZE)
size = MIN_FONT_SIZE;
else if( size > MAX_FONT_SIZE)
size = MAX_FONT_SIZE;
[[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)size forKey:PREFS_ITEMS_LIST_FONT_SIZE];
}
+ (CGFloat) itemsListFontSize
{
NSInteger size = [[NSUserDefaults standardUserDefaults] integerForKey:PREFS_ITEMS_LIST_FONT_SIZE];
if( size < MIN_FONT_SIZE || size > MAX_FONT_SIZE)
{
return STANDARD_ITEMS_LIST_FONT_SIZE;
}
return (CGFloat)size;
}
+ (void) increaseItemsListFontSize
{
[self setItemsListFontSize:[self itemsListFontSize] + 1];
}
+ (void) decreaseItemsListFontSize
{
[self setItemsListFontSize:[self itemsListFontSize] - 1];
}
+ (void) changeItemsListFontSize:(int)change
{
[self setItemsListFontSize:[self itemsListFontSize] + change];
}
+ (BOOL) canIncreaseItemsListFontSize
{
return [self itemsListFontSize] < MAX_FONT_SIZE;
}
+ (BOOL) canDecreaseItemsListFontSize
{
return [self itemsListFontSize] > MIN_FONT_SIZE;
}
+ (void) setDetailsFontSize:(NSInteger)size
{
if( size < MIN_FONT_SIZE)
size = MIN_FONT_SIZE;
else if( size > MAX_FONT_SIZE)
size = MAX_FONT_SIZE;
[[NSUserDefaults standardUserDefaults] setInteger:(NSInteger)size forKey:PREFS_DETAILS_FONT_SIZE];
}
+ (CGFloat) detailsFontSize
{
NSInteger size = [[NSUserDefaults standardUserDefaults] integerForKey:PREFS_DETAILS_FONT_SIZE];
if( size < MIN_FONT_SIZE || size > MAX_FONT_SIZE)
{
return STANDARD_DETAILS_VIEW_FONT_SIZE;
}
return (CGFloat)size;
}
+ (void) increaseDetailsFontSize
{
[self setDetailsFontSize:[self detailsFontSize] + 1];
}
+ (void) decreaseDetailsFontSize
{
[self setDetailsFontSize:[self detailsFontSize] - 1];
}
+ (void) changeDetailsFontSize:(int)change
{
[self setDetailsFontSize:[self detailsFontSize] + change];
}
+ (BOOL) canIncreaseDetailsFontSize
{
return [self detailsFontSize] < MAX_FONT_SIZE;
}
+ (BOOL) canDecreaseDetailsFontSize
{
return [self detailsFontSize] > MIN_FONT_SIZE;
}
+ (void) setUseGroupingForItems:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_USE_GROUPING_FOR_ITEMS];
}
+ (BOOL) useGroupingForItems
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_USE_GROUPING_FOR_ITEMS];
if( obj )
return [obj boolValue];
else
return YES;
}
+ (void) setGroupNumbers:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_GROUP_NUMBERS];
}
+ (BOOL) groupNumbers
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_GROUP_NUMBERS];
if( obj )
return [obj boolValue];
else
return YES;
}
+ (void) setUseMonospacedFont:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_USE_MONOSPACED_FONT];
}
+ (BOOL) useMonospacedFont
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_USE_MONOSPACED_FONT];
if( obj )
return [obj boolValue];
else
return NO;
}
+ (void) setFixedWidthsAlternative:(FixedWidthAlternative)alt
{
[[NSUserDefaults standardUserDefaults] setInteger:alt forKey:PREFS_FIXED_WIDTHS_ALTERNATIVE];
}
+ (FixedWidthAlternative) fixedWidthsAlternative
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_FIXED_WIDTHS_ALTERNATIVE];
if( obj )
return (FixedWidthAlternative)[obj integerValue];
else
return NO_FIXED_WIDTHS;
}
+ (void) setKeepQuotes:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_KEEP_QUOTES];
}
+ (BOOL) keepQuotes
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_KEEP_QUOTES];
}
+ (void) setUseCorrectParsing:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_USE_CORRECT_PARSING];
}
+ (BOOL) useCorrectParsing
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_USE_CORRECT_PARSING];
}
+ (void) setShowInlineImages:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_SHOW_INLINE_IMAGES];
}
+ (BOOL) showInlineImages
{
if( [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_SHOW_INLINE_IMAGES] )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_SHOW_INLINE_IMAGES];
else
return YES;
}
+ (void) setSmartSearchClearing:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING];
}
+ (BOOL) smartSeachClearing
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING];
if( obj )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING];
else
return YES;
}
+ (void) setUseAutomatedDownload:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_USE_AUTOMATED_DOWNLOAD];
}
+ (BOOL) useAutomatedDownload
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_USE_AUTOMATED_DOWNLOAD];
if( obj )
return [obj boolValue];
else
return NO;
}
+ (BOOL) isHourOK:(NSInteger)hour
{
return hour >= 0 && hour <= 23;
}
+ (BOOL) isMinuteOK:(NSInteger)minute
{
return minute >= 0 && minute <= 59;
}
+ (void) setConfiguredDownloadHour:(NSInteger)hour minute:(NSInteger)minute
{
if( [self isHourOK:hour] && [self isMinuteOK:minute])
{
NSString *time = [NSString stringWithFormat:@"%02ld:%02ld", (long)hour, (long)minute];
[[NSUserDefaults standardUserDefaults] setObject:time forKey:PREFS_CONFIGURED_DOWNLOAD_TIME];
}
}
+ (NSInteger) configuredDownloadHour
{
NSString *time = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_CONFIGURED_DOWNLOAD_TIME];
if( [time isKindOfClass:[NSString class]])
{
NSArray *hourminute = [time componentsSeparatedByString:@":"];
if( [hourminute count] == 2 )
{
NSInteger hour = [[hourminute objectAtIndex:0] integerValue];
if( [self isHourOK:hour])
{
return hour;
}
}
}
return 12;
}
+ (NSInteger) configuredDownloadMinute
{
NSString *time = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_CONFIGURED_DOWNLOAD_TIME];
if( [time isKindOfClass:[NSString class]])
{
NSArray *hourminute = [time componentsSeparatedByString:@":"];
if( [hourminute count] == 2 )
{
NSInteger minute = [[hourminute objectAtIndex:1] integerValue];
if( [self isMinuteOK:minute])
{
return minute;
}
}
}
return 00;
}
+ (NSDate *) nextDownload
{
if( ![CSVPreferencesController useAutomatedDownload])
{
return nil;
}
// So we have a configured time or rather, unfortunately, a date, where only time part is
// relevant. Next download is either today's date with this time, or tomorrow with this time.
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
NSDateComponents *todayComponents = [gregorian components: NSUIntegerMax
fromDate: today];
todayComponents.hour = [self configuredDownloadHour];
todayComponents.minute = [self configuredDownloadMinute];
todayComponents.second = 0;
NSDate *configuredToday = [gregorian dateFromComponents:todayComponents];
if( [configuredToday compare:today] == NSOrderedDescending)
{
return configuredToday;
}
else
{
NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
dayComponent.day = 1;
NSCalendar *theCalendar = [NSCalendar currentCalendar];
return [theCalendar dateByAddingComponents:dayComponent toDate:configuredToday options:0];
}
}
+ (NSDate *) lastDownload
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_LAST_DOWNLOAD];
if( [obj isKindOfClass:[NSDate class]] )
return obj;
else
return nil;
}
+ (void) setLastDownload:(NSDate *)lastDownload
{
[[NSUserDefaults standardUserDefaults] setObject:lastDownload forKey:PREFS_LAST_DOWNLOAD];
}
+ (void) setBlankWordSeparator:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_BLANK_WORD_SEPARATOR];
}
+ (BOOL) blankWordSeparator
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_BLANK_WORD_SEPARATOR];
if( obj )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_BLANK_WORD_SEPARATOR];
else
return NO;
}
+ (NSURL *) lastUsedListURL
{
if( [[NSUserDefaults class] respondsToSelector:@selector(URLForKey:)] )
return [[NSUserDefaults standardUserDefaults] URLForKey:LAST_USED_LIST_URL];
else
return [NSURL URLWithString:[[NSUserDefaults standardUserDefaults] stringForKey:LAST_USED_LIST_URL]];
}
+ (void) setLastUsedListURL:(NSURL *)URL
{
if( [[NSUserDefaults class] respondsToSelector:@selector(setURL:forKey:)] )
[[NSUserDefaults standardUserDefaults] setURL:URL forKey:LAST_USED_LIST_URL];
else
[[NSUserDefaults standardUserDefaults] setObject:[URL absoluteString] forKey:LAST_USED_LIST_URL];
}
+ (BOOL) canSynchronizeFiles
{
NSURL *last = [self lastUsedListURL];
return last != nil && [last absoluteString] != nil && ![[last absoluteString] isEqualToString:@""];
}
static BOOL hideAdress = NO;
+ (BOOL) hideAddress
{
return hideAdress;
}
+ (void) setHideAddress:(BOOL)hide
{
hideAdress = hide;
}
+ (void) applySettings:(NSArray *)settings
{
for( NSString *s in settings )
{
NSArray *words = [s componentsSeparatedByString:@" "];
if( [words count] == 2 )
{
if( [[words objectAtIndex:0] isEqualToString:PREFS_ENCODING] )
[[NSUserDefaults standardUserDefaults] setInteger:[[words objectAtIndex:1] intValue]
forKey:PREFS_ENCODING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_DELIMITER] )
[[NSUserDefaults standardUserDefaults] setObject:[words objectAtIndex:1]
forKey:PREFS_DELIMITER];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_SORTING_MASK] )
[[NSUserDefaults standardUserDefaults] setInteger:[[words objectAtIndex:1] intValue]
forKey:PREFS_SORTING_MASK];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_USE_GROUPING_FOR_ITEMS] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_USE_GROUPING_FOR_ITEMS];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_GROUP_NUMBERS] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_GROUP_NUMBERS];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_USE_MONOSPACED_FONT] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_USE_MONOSPACED_FONT];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_FIXED_WIDTHS_ALTERNATIVE] )
[[NSUserDefaults standardUserDefaults] setInteger:[[words objectAtIndex:1] integerValue]
forKey:PREFS_FIXED_WIDTHS_ALTERNATIVE];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_KEEP_QUOTES] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_KEEP_QUOTES];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_USE_CORRECT_PARSING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_USE_CORRECT_PARSING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_USE_CORRECT_SORTING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_USE_CORRECT_SORTING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_SHOULD_SORT] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_SHOULD_SORT];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_SHOW_INLINE_IMAGES] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_SHOW_INLINE_IMAGES];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_NUMBER_SENSITIVE_SORTING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_NUMBER_SENSITIVE_SORTING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_CASE_SENSITIVE_SORTING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_CASE_SENSITIVE_SORTING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_LITERAL_SORTING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_LITERAL_SORTING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_CLEAR_SEARCH_WHEN_QUICK_SELECTING];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_HIDE_ADDRESS] )
[CSVPreferencesController setHideAddress:[[words objectAtIndex:1] boolValue]];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_SHOW_DELETED_COLUMNS] )
[CSVPreferencesController setShowDeletedColumns:[[words objectAtIndex:1] boolValue]];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_HIDE_EMPTY_COLUMNS] )
[CSVPreferencesController setHideEmptyColumns:[[words objectAtIndex:1] boolValue]];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_BLANK_WORD_SEPARATOR] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_BLANK_WORD_SEPARATOR];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_MULTILINE_ITEM_CELLS] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_MULTILINE_ITEM_CELLS];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_SYNCHRONIZE_DOWNLOADED_FILES] )
[[NSUserDefaults standardUserDefaults] setBool:[[words objectAtIndex:1] boolValue]
forKey:PREFS_SYNCHRONIZE_DOWNLOADED_FILES];
else if( [[words objectAtIndex:0] isEqualToString:PREFS_CONFIGURED_DOWNLOAD_TIME] )
{
NSArray *time = [(NSString *)[words objectAtIndex:1] componentsSeparatedByString:@":"];
if( [time count] == 2)
{
[CSVPreferencesController setConfiguredDownloadHour:[[time objectAtIndex:0] integerValue]
minute:[[time objectAtIndex:1] integerValue]];
}
}
}
[self updateSortingMask];
[self updateFastCache];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL) restrictedDataVersionRunning
{
#ifdef CSV_LITE
return YES;
#else
return NO;
#endif
}
+ (BOOL) hasShownHowTo
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_HAS_SHOWN_HOW_TO];
if( obj )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_HAS_SHOWN_HOW_TO];
else
return NO;
}
+ (void) setHasShownHowTo
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:PREFS_HAS_SHOWN_HOW_TO];
}
+ (BOOL) hasShown40Notes
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_HAS_SHOWN_40_NOTES];
if( obj )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_HAS_SHOWN_40_NOTES];
else
return NO;
}
+ (void) setHasShown40Notes
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:PREFS_HAS_SHOWN_40_NOTES];
}
+ (BOOL) hasShown42ResizingNotes
{
id obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_HAS_SHOWN_42_RESIZING_NOTE];
if( obj )
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_HAS_SHOWN_42_RESIZING_NOTE];
else
return NO;
}
+ (void) setHasShown42ResizingNotes
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:PREFS_HAS_SHOWN_42_RESIZING_NOTE];
}
+ (void) setShouldSort:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_SHOULD_SORT];
}
+ (BOOL) shouldSort
{
id obj;
obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_SHOULD_SORT];
if( obj )
return [obj boolValue];
else
return TRUE;
}
+ (void) setCaseSensitiveSort:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_CASE_SENSITIVE_SORTING];
[self updateSortingMask];
}
+ (BOOL) caseSensitiveSort
{
id obj;
obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_CASE_SENSITIVE_SORTING];
if( obj )
return [obj boolValue];
else
return FALSE;
}
+ (void) setNumericSort:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_NUMBER_SENSITIVE_SORTING];
[self updateSortingMask];
}
+ (BOOL) numericSort
{
id obj;
obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_NUMBER_SENSITIVE_SORTING];
if( obj )
return [obj boolValue];
else
return TRUE;
}
+ (void) setLiteralSort:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_LITERAL_SORTING];
[self updateSortingMask];
}
+ (BOOL) literalSort
{
id obj;
obj = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_LITERAL_SORTING];
if( obj )
return [obj boolValue];
else
return TRUE;
}
+ (void) setCorrectSort:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_USE_CORRECT_SORTING];
}
+ (BOOL) correctSort
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_USE_CORRECT_SORTING];
}
+ (void) setMultilineItemCells:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_MULTILINE_ITEM_CELLS];
}
+ (BOOL) multilineItemCells
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_MULTILINE_ITEM_CELLS];
}
+ (void) setSynchronizeDownloadedFiles:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_SYNCHRONIZE_DOWNLOADED_FILES];
}
+ (BOOL) synchronizeDownloadedFiles
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_SYNCHRONIZE_DOWNLOADED_FILES];
}
+ (void) updateFastCache
{
_cachedReverseSorting = [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_REVERSE_ITEM_SORTING];
}
+ (void) updateSortingMask
{
// Default, so make sure default return values above correlates to these defaults
sortingMask = 0;
if( ![self caseSensitiveSort])
sortingMask ^= NSCaseInsensitiveSearch;
if( [self numericSort])
sortingMask ^= NSNumericSearch;
if( [self literalSort])
sortingMask ^= NSLiteralSearch;
}
+ (NSUInteger) sortingMask
{
NSString *sorting = [[NSUserDefaults standardUserDefaults] objectForKey:PREFS_SORTING_MASK];
if( sorting )
sortingMask = [sorting intValue];
else
sortingMask = NSNumericSearch ^ NSCaseInsensitiveSearch;
return sortingMask;
}
+ (void) toggleReverseItemSorting
{
_cachedReverseSorting = !_cachedReverseSorting;
[[NSUserDefaults standardUserDefaults] setBool:_cachedReverseSorting forKey:PREFS_REVERSE_ITEM_SORTING];
}
+ (BOOL) reverseItemSorting
{
return _cachedReverseSorting;
}
+ (NSString *) lastUsedURL
{
return [[NSUserDefaults standardUserDefaults] objectForKey:NEW_FILE_URL];
}
+ (void) setLastUsedURL:(NSString *)URL
{
if( URL )
{
[[NSUserDefaults standardUserDefaults] setObject:URL
forKey:NEW_FILE_URL];
}
else
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:NEW_FILE_URL];
}
}
+ (NSInteger) selectedDetailsView
{
return [[NSUserDefaults standardUserDefaults] integerForKey:PREFS_DETAILS_VIEW];
}
+ (void) setSelectedDetailsView:(NSInteger)view
{
[[NSUserDefaults standardUserDefaults] setInteger:view forKey:PREFS_DETAILS_VIEW];
}
+ (BOOL) showDeletedColumns
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_SHOW_DELETED_COLUMNS];
}
+ (void) setShowDeletedColumns:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_SHOW_DELETED_COLUMNS];
}
+ (BOOL) hideEmptyColumns
{
return [[NSUserDefaults standardUserDefaults] boolForKey:PREFS_HIDE_EMPTY_COLUMNS];
}
+ (void) setHideEmptyColumns:(BOOL)yn
{
[[NSUserDefaults standardUserDefaults] setBool:yn forKey:PREFS_HIDE_EMPTY_COLUMNS];
}
+ (NSInteger) numberOfStarts
{
return [[NSUserDefaults standardUserDefaults] integerForKey:NUMBER_OF_STARTS];
}
static NSDictionary *oldDefaults = nil;
+ (BOOL) defaultsHaveChanged
{
return ![[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] isEqual:oldDefaults];
}
+ (void) resetDefaultsHaveChanges
{
oldDefaults = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] copy];
}
+ (UIColor *) systemBackgroundColor
{
if (@available(iOS 13, *))
return [UIColor systemBackgroundColor];
else
return [UIColor whiteColor];
}
@end