-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathController.m
3543 lines (3160 loc) · 112 KB
/
Controller.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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "Controller.h"
#import "CustomWindow.h"
#import "BookmarkController.h"
#import "CustomImageView.h"
#import "FullImagePanel.h"
@implementation Controller
static const int DIALOG_OK = 128;
static const int DIALOG_CANCEL = 129;
/*
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[lock lock];
[lock unlock];
[pool release];
[NSThread exit];
[NSThread detachNewThreadSelector:@selector(lookaheadThread) toTarget:self withObject:nil];
*/
/*
NSTimeInterval start,stop,elapsed;
start=[NSDate timeIntervalSinceReferenceDate];
//処理
stop=[NSDate timeIntervalSinceReferenceDate];
elapsed=stop-start;
NSLog(@"%f",elapsed);
*/
-(void)awakeFromNib
{
threadCount = 0;
imageLoader = nil;
wheelUpTimer = nil;
wheelDownTimer = nil;
lock = [[NSLock allocWithZone:NULL] init];
//lock = [[NSConditionLock allocWithZone:NULL] initWithCondition:0];
//composeLock = [[NSLock allocWithZone:NULL] init];
[imageView setTarget:self];
defaults = [NSUserDefaults standardUserDefaults];
#pragma mark default
BOOL openLastFolder;
BOOL fullscreen;
NSMutableDictionary *appDefault = [NSMutableDictionary dictionary];
if([NSObject respondsToSelector:@selector(finalize)]){
bufferingMode = 1;
[appDefault setObject:[NSNumber numberWithInt:bufferingMode] forKey:@"BufferingMode"];
}
openLastFolder = YES;
fullscreen = YES;
wheelSensitivity = 1.0;
[appDefault setObject:[NSNumber numberWithBool:openLastFolder] forKey:@"OpenLastFolder"];
[appDefault setObject:[NSNumber numberWithBool:fullscreen] forKey:@"Fullscreen"];
[appDefault setObject:[NSNumber numberWithFloat:wheelSensitivity] forKey:@"WheelSensitivity"];
[appDefault setObject:[NSNumber numberWithInt:0] forKey:@"PrevPageMode"];
[appDefault setObject:[NSNumber numberWithInt:0] forKey:@"CanScrollMode"];
[appDefault setObject:[NSNumber numberWithInt:2] forKey:@"PrevPagePageBarPositionMode"];
[appDefault setObject:[NSNumber numberWithBool:YES] forKey:@"ShowPageBar"];
[appDefault setObject:[NSNumber numberWithBool:YES] forKey:@"ShowNumber"];
[appDefault setObject:[NSNumber numberWithInt:10] forKey:@"OpenRecentLimit"];
[defaults registerDefaults:appDefault];
fitScreenMode = 0;
rotateMode=0;
if (![defaults arrayForKey:@"KeyArray"]) [PreferenceController setDefaultKeyArray];
if (![defaults arrayForKey:@"KeyArrayMode2"]) [PreferenceController setDefaultKeyArrayMode2];
if (![defaults arrayForKey:@"KeyArrayMode3"]) [PreferenceController setDefaultKeyArrayMode3];
keyArray = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"KeyArray"]];
keyArrayMode2 = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"KeyArrayMode2"]];
keyArrayMode3 = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"KeyArrayMode3"]];
if (![defaults arrayForKey:@"MouseArray"]) [PreferenceController setDefaultMouseArray];
if (![defaults arrayForKey:@"MouseArrayMode2"]) [PreferenceController setDefaultMouseArrayMode2];
if (![defaults arrayForKey:@"MouseArrayMode3"]) [PreferenceController setDefaultMouseArrayMode3];
mouseArray = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"MouseArray"]];
mouseArrayMode2 = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"MouseArrayMode2"]];
mouseArrayMode3 = [[NSMutableArray alloc] initWithArray:[defaults arrayForKey:@"MouseArrayMode3"]];
int skipPage = (int)[defaults integerForKey:@"SkipPage"];
if (skipPage == 0) {
skipPage = 10;
}
NSEnumerator *enu = [keyArray objectEnumerator];
id dic;
id newDic;
while (dic = [enu nextObject]) {
if (![dic valueForKey:@"value"]) {
switch ([[dic objectForKey:@"action"] intValue]) {
case 13: case 14:
newDic = [NSMutableDictionary dictionaryWithDictionary:dic];
[newDic setObject:[NSNumber numberWithInt:skipPage] forKey:@"value"];
[keyArray replaceObjectAtIndex:[keyArray indexOfObject:dic] withObject:newDic];
break;
default:
break;
}
}
}
[defaults setObject:keyArray forKey:@"KeyArray"];
enu = [mouseArray objectEnumerator];
while (dic = [enu nextObject]) {
if (![dic valueForKey:@"value"]) {
switch ([[dic objectForKey:@"action"] intValue]) {
case 5: case 19: case 20:
newDic = [NSMutableDictionary dictionaryWithDictionary:dic];
[newDic setObject:[NSNumber numberWithInt:skipPage] forKey:@"value"];
[mouseArray replaceObjectAtIndex:[mouseArray indexOfObject:dic] withObject:newDic];
break;
default:
break;
}
}
}
[defaults setObject:mouseArray forKey:@"MouseArray"];
#pragma mark normal
if (![defaults dictionaryForKey:@"BookSettings"]) {
[defaults setObject:[NSMutableDictionary dictionary] forKey:@"BookSettings"];
}
//bookSettings = [[NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:@"BookSettings"]] retain];
if (![defaults arrayForKey:@"RecentItems"]) {
[defaults setObject:[NSMutableArray array] forKey:@"RecentItems"];
}
//recentItems = [[NSMutableArray arrayWithArray:[defaults arrayForKey:@"BookSettings"]] retain];
interpolation = (int)[defaults integerForKey:@"Interpolation"];
[imageView setInterpolation:interpolation];
[defaults setInteger:interpolation forKey:@"Interpolation"];
BOOL useCalayer = [defaults boolForKey:@"UseCALayer"];
[imageView setUseCalayer:useCalayer];
[defaults setBool:useCalayer forKey:@"UseCALayer"];
cacheSize = (int)[defaults integerForKey:@"ImageCache"];
[defaults setInteger:cacheSize forKey:@"ImageCache"];
screenCache = (int)[defaults integerForKey:@"ScreenCache"];
[defaults setInteger:screenCache forKey:@"ScreenCache"];
int thumbnailCache = (int)[defaults integerForKey:@"ThumbnailCache"];
[defaults setInteger:thumbnailCache forKey:@"ThumbnailCache"];
/*history*/
alwaysRememberLastPage = [defaults boolForKey:@"AlwaysRememberLastPage"];
[defaults setBool:alwaysRememberLastPage forKey:@"AlwaysRememberLastPage"];
goToLastPageMode = (int)[defaults integerForKey:@"GoToLastPage"];
[defaults setInteger:goToLastPageMode forKey:@"GoToLastPage"];
openRecentLimit = (int)[defaults integerForKey:@"OpenRecentLimit"];
/*loupe*/
int loupeSize = (int)[defaults integerForKey:@"LoupeSize"];
if (!loupeSize) loupeSize = 150;
[defaults setInteger:loupeSize forKey:@"LoupeSize"];
float loupeRate = [defaults floatForKey:@"LoupeRate"];
if (!loupeRate) loupeRate = 1.0;
[defaults setFloat:loupeRate forKey:@"LoupeRate"];
/*view*/
NSColor *viewBackGround;
if ([defaults objectForKey:@"ViewBackGroundColor"]) {
viewBackGround = [NSUnarchiver unarchiveObjectWithData:[defaults objectForKey:@"ViewBackGroundColor"]];
} else {
viewBackGround = [NSColor blackColor];
}
[window setBackgroundColor:viewBackGround];
viewBackGround = [viewBackGround colorWithAlphaComponent:1];
fullscreen = [defaults boolForKey:@"Fullscreen"];
if (!fullscreen) {
[[[[[NSApp mainMenu] itemWithTitle:NSLocalizedString(@"Window", @"")] submenu] itemWithTitle:NSLocalizedString(@"Fullscreen", @"")] setState:NSOffState];
}
bufferingMode = (int)[defaults integerForKey:@"BufferingMode"];
[defaults setInteger:bufferingMode forKey:@"BufferingMode"];
BOOL fitOriginal = [defaults boolForKey:@"FitOriginal"];
[fullImagePanel setFitMode:fitOriginal];
[defaults setBool:fitOriginal forKey:@"FitOriginal"];
readMode = (int)[defaults integerForKey:@"ReadMode"];
[defaults setInteger:readMode forKey:@"ReadMode"];
rememberBookSettings = [defaults boolForKey:@"RememberBookSettings"];
[defaults setBool:rememberBookSettings forKey:@"RememberBookSettings"];
NSDictionary *thumbnail = [defaults dictionaryForKey:@"Thumbnail"];
if (!thumbnail) thumbnail = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:2],@"row",[NSNumber numberWithInt:3],@"column",nil];
[thumController setCellRow:[[thumbnail objectForKey:@"row"] intValue]
column:[[thumbnail objectForKey:@"column"] intValue]];
[defaults setObject:thumbnail forKey:@"Thumbnail"];
sliderValue = [defaults floatForKey:@"SlideshowDelay"];
loopCheck = (int)[defaults integerForKey:@"LoopCheck"];
pageBar = [defaults boolForKey:@"ShowPageBar"];
if (![defaults dictionaryForKey:@"PageBarSize"]) {
[defaults setObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:200],@"width",[NSNumber numberWithInt:15],@"height",nil]
forKey:@"PageBarSize"];
}
numberSwitch = [defaults boolForKey:@"ShowNumber"];
maxEnlargement = (int)[defaults integerForKey:@"MaxEnlargement"];
singleSetting = (int)[defaults integerForKey:@"SingleSetting"];
if (!singleSetting) {
singleSetting = 740;
}
[defaults setInteger:singleSetting forKey:@"SingleSetting"];
readSubFolder = [defaults boolForKey:@"ReadSubFolder"];
wheelSensitivity = [defaults floatForKey:@"WheelSensitivity"];
[imageView wheelSetting:wheelSensitivity];
[thumController wheelSetting:wheelSensitivity];
prevPageMode = (int)[defaults integerForKey:@"PrevPageMode"];
canScrollMode = (int)[defaults integerForKey:@"CanScrollMode"];
[defaults setFloat:sliderValue forKey:@"SlideshowDelay"];
[defaults setFloat:wheelSensitivity forKey:@"WheelSensitivity"];
[defaults setInteger:loopCheck forKey:@"LoopCheck"];
[defaults setBool:numberSwitch forKey:@"ShowNumber"];
[defaults setInteger:maxEnlargement forKey:@"MaxEnlargement"];
[defaults setBool:fullscreen forKey:@"Fullscreen"];
[defaults setBool:readSubFolder forKey:@"ReadSubFolder"];
screenCacheArray = [[NSMutableArray allocWithZone:NULL] init];
cacheArray = [[NSMutableArray allocWithZone:NULL] init];
imageMutableArray = [[NSMutableArray allocWithZone:NULL] init];
bookmarkArray = [[NSMutableArray allocWithZone:NULL] init];
currentBookSetting = [[NSMutableDictionary allocWithZone:NULL] init];
marksArray = [[NSMutableArray allocWithZone:NULL] init];
openLastFolder = [defaults boolForKey:@"OpenLastFolder"];
[defaults setBool:openLastFolder forKey:@"OpenLastFolder"];
[self setOpenRecentMenu];
if ([defaults boolForKey:@"DontHideMenuBar"]) {
[window setHideMenuBar:NO];
} else {
[window setHideMenuBar:YES];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(viewDidEndLiveResize:)
name:@"ViewDidEndLiveResize"
object:imageView];
openLinkMode = (int)[defaults integerForKey:@"OpenLinkMode"];
[defaults setInteger:openLinkMode forKey:@"OpenLinkMode"];
changeCurrentFolderMode = (int)[defaults integerForKey:@"ChangeCurrentFolder"];
[defaults setInteger:changeCurrentFolderMode forKey:@"ChangeCurrentFolder"];
NSString *oldVersion = [defaults stringForKey:@"Version"];
NSString *nowVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
#pragma mark only under 1.2b10
if (![defaults stringForKey:@"Version"]) {
if ([defaults dictionaryForKey:@"BookSettings"]) {
NSMutableDictionary *newBookSettings = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:@"BookSettings"]];
NSEnumerator *settingKeyEnu = [[defaults dictionaryForKey:@"BookSettings"] keyEnumerator];
id settingKey;
id setting;
while (settingKey = [settingKeyEnu nextObject]) {
setting = [newBookSettings objectForKey:settingKey];
NSMutableDictionary *newSetting = [NSMutableDictionary dictionaryWithDictionary:setting];
[newSetting setObject:[self pathFromAliasData:[setting objectForKey:@"alias"]] forKey:@"temppath"];
[newBookSettings setObject:newSetting forKey:settingKey];
}
[defaults setObject:newBookSettings forKey:@"BookSettings"];
}
if ([defaults arrayForKey:@"LastPages"]) {
NSMutableArray *newLastPages = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"LastPages"]];
NSEnumerator *enu = [[defaults arrayForKey:@"LastPages"] objectEnumerator];
id object;
while (object = [enu nextObject]) {
int index = (int)[newLastPages indexOfObject:object];
if ([[object objectForKey:@"page"] intValue] == 0) {
[newLastPages removeObjectAtIndex:index];
} else {
NSMutableDictionary *newInnerDic = [NSMutableDictionary dictionaryWithDictionary:object];
[newLastPages removeObjectAtIndex:index];
[newInnerDic setObject:[self pathFromAliasData:[object objectForKey:@"alias"]] forKey:@"temppath"];
[newLastPages addObject:newInnerDic];
}
}
[defaults setObject:newLastPages forKey:@"LastPages"];
}
if ([defaults arrayForKey:@"RecentItems"]) {
NSMutableArray *newRecentItems = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"RecentItems"]];
NSEnumerator *enu = [[defaults arrayForKey:@"RecentItems"] objectEnumerator];
id object;
while (object = [enu nextObject]) {
NSMutableDictionary *newInnerDic = [NSMutableDictionary dictionaryWithDictionary:object];
int index = (int)[[defaults arrayForKey:@"RecentItems"] indexOfObject:object];
[newRecentItems removeObjectAtIndex:index];
[newInnerDic setObject:[self pathFromAliasData:[object objectForKey:@"alias"]] forKey:@"temppath"];
[newRecentItems insertObject:newInnerDic atIndex:index];
}
[defaults setObject:newRecentItems forKey:@"RecentItems"];
}
}
#pragma mark only under 1.2b14
if ([@"1.2b14" versionCompare:oldVersion] == NSOrderedDescending && [defaults stringForKey:@"Version"]) {
unichar plus = kRemoteButtonPlus;
unichar minus = kRemoteButtonMinus;
unichar menu = kRemoteButtonMenu;
unichar play = kRemoteButtonPlay;
unichar right = kRemoteButtonRight;
unichar left = kRemoteButtonLeft;
NSArray *numericKeyArray = [[NSMutableArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"0",@"keyname", [NSString stringWithFormat:@"0"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:0],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"1",@"keyname", [NSString stringWithFormat:@"1"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:10],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"2",@"keyname", [NSString stringWithFormat:@"2"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:20],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"3",@"keyname", [NSString stringWithFormat:@"3"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:30],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"4",@"keyname", [NSString stringWithFormat:@"4"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:40],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"5",@"keyname", [NSString stringWithFormat:@"5"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:50],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"6",@"keyname", [NSString stringWithFormat:@"6"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:60],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"7",@"keyname", [NSString stringWithFormat:@"7"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:70],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"8",@"keyname", [NSString stringWithFormat:@"8"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:80],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:39],@"action",@"9",@"keyname", [NSString stringWithFormat:@"9"],@"key",
[NSNumber numberWithInt:0],@"modifier",[NSNumber numberWithInt:90],@"value",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:7],@"action",
@"AppleRemote Volume up",@"keyname", [NSString stringWithCharacters:&plus length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:6],@"action",
@"AppleRemote Volume down",@"keyname", [NSString stringWithCharacters:&minus length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:18],@"action",
@"AppleRemote Menu",@"keyname", [NSString stringWithCharacters:&menu length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:17],@"action",
@"AppleRemote Play",@"keyname", [NSString stringWithCharacters:&play length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:1],@"action",
@"AppleRemote Right",@"keyname", [NSString stringWithCharacters:&right length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
[NSNumber numberWithBool:YES],@"switchAction",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:0],@"action",
@"AppleRemote Left",@"keyname", [NSString stringWithCharacters:&left length:1],@"key",
[NSNumber numberWithInt:100],@"modifier",
[NSNumber numberWithBool:YES],@"switchAction",
nil],
nil];
[keyArray addObjectsFromArray:numericKeyArray];
[defaults setObject:keyArray forKey:@"KeyArray"];
[numericKeyArray release];
if ([defaults objectForKey:@"PageBarBGColor"]) {
[defaults setObject:[NSArchiver archivedDataWithRootObject:
[[NSUnarchiver unarchiveObjectWithData:[defaults objectForKey:@"PageBarBGColor"]] colorWithAlphaComponent:0.8]] forKey:@"PageBarBGColor"];
}
}
if ([@"1.2b17" versionCompare:oldVersion] == NSOrderedDescending && [defaults stringForKey:@"Version"]) {
[mouseArray addObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:59],@"action",
[NSNumber numberWithInt:1],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil]];
[mouseArray addObject:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:59],@"action",
[NSNumber numberWithInt:0],@"button",
[NSNumber numberWithInt:4],@"modifier",
nil]];
[defaults setObject:mouseArray forKey:@"MouseArray"];
}
if ([@"1.2b23" versionCompare:oldVersion] == NSOrderedDescending && [defaults stringForKey:@"Version"]) {
NSArray *multiTouchMouseArray = [[NSMutableArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:6],@"action",
[NSNumber numberWithInt:2000],@"button",
[NSNumber numberWithInt:0],@"modifier",
[NSNumber numberWithBool:YES],@"switchAction",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:7],@"action",
[NSNumber numberWithInt:1000],@"button",
[NSNumber numberWithInt:0],@"modifier",
[NSNumber numberWithBool:YES],@"switchAction",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:14],@"action",
[NSNumber numberWithInt:4000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:15],@"action",
[NSNumber numberWithInt:3000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:49],@"action",
[NSNumber numberWithInt:7000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:50],@"action",
[NSNumber numberWithInt:8000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:63],@"action",
[NSNumber numberWithInt:6000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:64],@"action",
[NSNumber numberWithInt:5000],@"button",
[NSNumber numberWithInt:0],@"modifier",
nil],
nil];
[mouseArray addObjectsFromArray:multiTouchMouseArray];
[defaults setObject:mouseArray forKey:@"MouseArray"];
}
#pragma mark versionCompareTest
//versionCompare_test
//1.2b10〜
/*
NSString *plist = oldVersion;
NSString *nowVer = nowVersion;
plist = @"";
nowVer = @"1.2b14";
NSComparisonResult result = [nowVer versionCompare:plist];
if (result == NSOrderedAscending) {
NSLog(@"%@ %@ left is small",nowVer,plist);
} else if (result == NSOrderedSame) {
NSLog(@"%@ %@ equal",nowVer,plist);
} else if (result == NSOrderedDescending) {
NSLog(@"%@ %@ left is big",nowVer,plist);
} else {
NSLog(@"%@ %@ err",nowVer,plist);
}*/
#pragma mark set Version
if ([nowVersion versionCompare:oldVersion] == NSOrderedDescending) {
//NSLog(@"%@ %@ left is big",nowVer,plist);
[defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"Version"];
}
[self setupRemoteControl];
[imageView setPreferences];
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
NSEnumerator *enu = [keyArray objectEnumerator];
id object;
NSMutableArray *array = [NSMutableArray arrayWithArray:keyArray];
[fullImagePanel setPageKey:array];
[thumController setPageKey:array];
NSMutableArray *array2 = [NSMutableArray array];
enu = [mouseArrayMode2 objectEnumerator];
while (object = [enu nextObject]) {
if ([[object objectForKey:@"action"] intValue] == 41) {
[array2 addObject:object];
}
}
[imageView setDragScroll:array2 mode:1];
NSMutableArray *array3 = [NSMutableArray array];
enu = [mouseArrayMode3 objectEnumerator];
while (object = [enu nextObject]) {
if ([[object objectForKey:@"action"] intValue] == 41) {
[array3 addObject:object];
}
}
[imageView setDragScroll:array3 mode:2];
[imageView setDragScroll:array3 mode:3];
if ([defaults boolForKey:@"OpenLastFolder"] == YES) {
if (![window isVisible]) {
[self openTheLastPage:self];
}
}
}
#pragma mark appleRemote
- (void)setupRemoteControl
{
remoteControl = [[AppleRemote alloc] initWithDelegate: self];
[remoteControl setDelegate: self];
// OPTIONAL CODE
// The MultiClickRemoteBehavior adds extra functionality.
// It works like a middle man between the delegate and the remote control
remoteControlBehavior = [MultiClickRemoteBehavior new];
[remoteControlBehavior setDelegate: self];
[remoteControlBehavior setSimulateHoldEvent:YES];
[remoteControl setOpenInExclusiveMode:YES];
[remoteControl setDelegate: remoteControlBehavior];
[remoteControl startListening: self];
}
- (void)applicationWillBecomeActive:(NSNotification *)aNotification {
[remoteControl startListening: self];
}
- (void)applicationWillResignActive:(NSNotification *)aNotification {
[remoteControl stopListening: self];
}
#pragma mark openFromAny
- (IBAction)openTheLastPage:(id)sender
{
if ([imageView image]) {
int page;
if ([defaults arrayForKey:@"RecentItems"]) {
id object = [self searchFromRecentItems:currentBookPath index:nil];
if (object) {
if ([object objectForKey:@"page"]) {
page = [[object objectForKey:@"page"] intValue];
[self goTo:page array:nil];
return;
}
}
}
if ([defaults arrayForKey:@"LastPages"]) {
NSEnumerator *enu = [[defaults arrayForKey:@"LastPages"] objectEnumerator];
id object;
while (object = [enu nextObject]) {
if ([[self pathFromAliasData:[object objectForKey:@"alias"]] isEqualToString:currentBookPath]) {
page = [[object objectForKey:@"page"] intValue];
[self goTo:page array:nil];
return;
}
}
}
} else {
if ([[defaults arrayForKey:@"RecentItems"] count]>0) {
NSArray *array = [defaults arrayForKey:@"RecentItems"];
[self setCurrentBookPath:[self pathFromAliasData:[[array objectAtIndex:0] objectForKey:@"alias"]]];
[self openPage:[[[array objectAtIndex:0] objectForKey:@"page"] intValue] last:NO];
}
}
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
if (timerSwitch) {
[timer invalidate];
timerSwitch=NO;
}
[self setCurrentBookPathAndOldBookPath:filename];
[self openPage:0 last:NO];
return NO;
}
-(IBAction)open:(id)sender
{
if (timerSwitch) {
[timer invalidate];
timerSwitch=NO;
}
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
int openPanelResult;
[openPanel setCanChooseDirectories:YES];
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:[COImageLoader fileTypes]];
[openPanel setAllowedFileTypes:tempArray];
openPanelResult = (int)[openPanel runModal];
if (openPanelResult == NSCancelButton) {
return;
}
if (openPanelResult == NSOKButton) {
if (timerSwitch) {
[timer invalidate];
timerSwitch=NO;
}
[self setCurrentBookPathAndOldBookPath:[[openPanel URL] path]];
[self openPage:0 last:NO];
}
}
-(void)openFromSameDir:(id)sender
{
[self openFromSameDir:sender last:NO];
}
-(void)openFromSameDir:(id)sender last:(BOOL)isLast
{
[self setCurrentBookPathAndOldBookPath:[sender representedObject]];
[self openPage:0 last:isLast];
}
-(void)openFromOpenRecent:(id)sender
{
[self setCurrentBookPathAndOldBookPath:[self pathFromAliasData:[[sender representedObject] objectForKey:@"alias"]]];
[self openPage:[[[sender representedObject] objectForKey:@"page"] intValue] last:NO];
}
#pragma mark openning
- (void)openPage:(int)page last:(BOOL)last;
{
[window makeKeyAndOrderFront:self];
[progressIndicator startAnimation:self];
[progressIndicator displayIfNeeded];
/*
[imageView lockFocus];
NSRect rect = [[window contentView] convertRect:[progressIndicator frame] toView:imageView];
rect = NSMakeRect(rect.origin.x-2,rect.origin.y-2,rect.size.width+4,rect.size.height+4);
NSBezierPath *bezier = [NSBezierPath bezierPath];
float rad = 10.0;
[bezier appendBezierPathWithArcWithCenter:NSMakePoint(rect.origin.x+rad,rect.origin.y+rect.size.height-rad)
radius:rad startAngle:90 endAngle:180];
[bezier appendBezierPathWithArcWithCenter:NSMakePoint(rect.origin.x+rad,rect.origin.y+rad)
radius:rad startAngle:180 endAngle:270];
[bezier appendBezierPathWithArcWithCenter:NSMakePoint(rect.origin.x+rect.size.width-rad,rect.origin.y+rad)
radius:rad startAngle:270 endAngle:0];
[bezier appendBezierPathWithArcWithCenter:NSMakePoint(rect.origin.x+rect.size.width-rad,rect.origin.y+rect.size.height-rad)
radius:rad startAngle:0 endAngle:90];
[bezier closePath];
[[[NSColor grayColor] colorWithAlphaComponent:0.8] set];
[bezier fill];
[imageView unlockFocus];
[imageView displayIfNeeded];
*/
NSString *fromFileName = nil;
if ([[NSImage imageFileTypes] containsObject:[[currentBookPath pathExtension] lowercaseString]]) {
if ([[currentBookPath pathExtension] compare:@"pdf" options:NSCaseInsensitiveSearch] != NSOrderedSame) {
fromFileName = currentBookPath;
[currentBookName release];
[currentBookAlias release];
[self setCurrentBookPath:[currentBookPath stringByDeletingLastPathComponent]];
}
}
COImageLoader *newImageLoader = [[COImageLoader alloc] initWithPath:currentBookPath readSubFolder:readSubFolder controller:self];
//NSLog(@"controller mode=%i count=%i",[newImageLoader mode],[newImageLoader itemCount]);
if (!newImageLoader || ![newImageLoader checkPassword] || [newImageLoader mode] < 0 || [newImageLoader itemCount] < 1) {
/*表示出来ない時は元に戻す*/
[newImageLoader release];
if ([imageView image]) {
/*ウィンドウを開いているとき*/
[currentBookPath release];
[currentBookName release];
[currentBookAlias release];
currentBookPath = oldBookPath;
currentBookName = oldBookName;
currentBookAlias = oldBookAlias;
[self setSameFolderMenu];
} else {
[currentBookPath release];
[currentBookName release];
[currentBookAlias release];
currentBookPath = nil;
currentBookName = nil;
currentBookAlias = nil;
[window performClose:self];
}
[progressIndicator stopAnimation:self];
//[imageView displayRect:rect];
return;
} else if ([imageView image]) {
/*ウィンドウを開いてたら準備する*/
//currentBookPathではなくoldBookPath
//currentBookNameではなくoldBookName
//なことに注意する事!
/*clear cache*/
[cacheArray removeAllObjects];
[screenCacheArray removeAllObjects];
if (oldBookPath != nil) {
NSData *aliasData = oldBookAlias;
/*bookmark&booksettings保存*/
NSMutableDictionary *dic;
if (![defaults dictionaryForKey:@"BookSettings"]) {
dic = [NSMutableDictionary dictionary];
} else {
dic = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:@"BookSettings"]];
}
id key;
[self searchFromBookSettings:oldBookPath key:&key];
[currentBookSetting setObject:aliasData forKey:@"alias"];
[currentBookSetting setObject:oldBookPath forKey:@"temppath"];
if ([bookmarkArray count]>0) {
[currentBookSetting setObject:bookmarkArray forKey:@"bookmarks"];
} else if ([bookmarkArray count]==0) {
[currentBookSetting removeObjectForKey:@"bookmarks"];
}
if ([currentBookSetting count]>2) {
if (!key) {
key = oldBookName;
int i = 2;
while ([dic objectForKey:key]) {
key = [NSString stringWithFormat:@"%@#%i",oldBookName,i];
i++;
}
[dic setObject:currentBookSetting forKey:key];
} else {
[dic setObject:currentBookSetting forKey:key];
}
[defaults setObject:dic forKey:@"BookSettings"];
}
/*historyの処理*/
if (secondImage) {
nowPage -= 2;
} else {
nowPage--;
}
NSNumber *pageNumber = [NSNumber numberWithInt:nowPage];
if (openRecentLimit>0) {
NSMutableArray *newRecentItems;
if (![defaults arrayForKey:@"RecentItems"]) {
newRecentItems = [NSMutableArray array];
} else {
newRecentItems = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"RecentItems"]];
}
int index = 0;
id object = [self searchFromRecentItems:oldBookPath index:&index];
if (object) {
[newRecentItems removeObjectAtIndex:index];
}
while ([newRecentItems count] >= openRecentLimit) {
[newRecentItems removeLastObject];
}
[newRecentItems insertObject:[NSDictionary dictionaryWithObjectsAndKeys:aliasData,@"alias",pageNumber,@"page",oldBookPath,@"temppath",nil] atIndex:0];
[defaults setObject:newRecentItems forKey:@"RecentItems"];
} else {
[defaults removeObjectForKey:@"RecentItems"];
}
if (alwaysRememberLastPage && nowPage > 0) {
NSMutableArray *lastPages;
if (![defaults arrayForKey:@"LastPages"]) {
lastPages = [NSMutableArray array];
} else {
lastPages = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"LastPages"]];
}
int index;
id object = [self searchFromLastPages:oldBookPath index:&index];
if (object) {
[lastPages removeObjectAtIndex:index];
}
[lastPages addObject:[NSDictionary dictionaryWithObjectsAndKeys:aliasData,@"alias",pageNumber,@"page",oldBookPath,@"temppath",nil]];
[defaults setObject:lastPages forKey:@"LastPages"];
} else if (!alwaysRememberLastPage || nowPage == 0) {
NSMutableArray *lastPages;
if (![defaults arrayForKey:@"LastPages"]) {
lastPages = [NSMutableArray array];
} else {
lastPages = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"LastPages"]];
}
int index;
id object = [self searchFromLastPages:oldBookPath index:&index];
if (object) {
[lastPages removeObjectAtIndex:index];
}
[defaults setObject:lastPages forKey:@"LastPages"];
}
}
[completeMutableArray release];
completeMutableArray = nil;
[imageMutableArray removeAllObjects];
[bookmarkArray removeAllObjects];
[currentBookSetting removeAllObjects];
[imageLoader release];
}
[self setSameFolderMenu];
if (oldBookPath != nil) {
[oldBookPath release];
[oldBookName release];
[oldBookAlias release];
oldBookPath = nil;
oldBookName = nil;
oldBookAlias = nil;
}
id tempCurrentBookSetting = [self searchFromBookSettings:currentBookPath key:nil more:YES];
if (tempCurrentBookSetting) {
[currentBookSetting setDictionary:tempCurrentBookSetting];
}
NSMutableArray *newRecentItems;
if (![defaults arrayForKey:@"RecentItems"]) {
newRecentItems = [NSMutableArray array];
} else {
newRecentItems = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"RecentItems"]];
}
NSMutableArray *lastPages;
if (![defaults arrayForKey:@"LastPages"]) {
lastPages = [NSMutableArray array];
} else {
lastPages = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"LastPages"]];
}
NSData *aliasData = currentBookAlias;
/*goto lastpage?*/
if (goToLastPageMode<2 && !last && page == 0) {
id object = [self searchFromRecentItems:currentBookPath index:nil];
if (object) {
page = [[object objectForKey:@"page"] intValue];
}
if (!page) {
object = [self searchFromLastPages:currentBookPath index:nil];
if (object) {
page = [[object objectForKey:@"page"] intValue];
}
}
if (goToLastPageMode==0 && page) {
int result = (int)NSRunAlertPanel(NSLocalizedString(@"Go to the last page",@""),
NSLocalizedString(@"Do you want to go to %i page?",@""),
NSLocalizedString(@"OK",@""),
NSLocalizedString(@"Cancel",@""),
nil,page+1);
if(result == NSAlertDefaultReturn || result == NSAlertFirstButtonReturn) {
} else {
page = 0;
}
}
}
/*add RecentItem*/
if (openRecentLimit>0) {
NSDictionary *newDic = [NSDictionary dictionaryWithObjectsAndKeys:aliasData,@"alias",currentBookPath,@"temppath",nil];
if (alwaysRememberLastPage) {
id object = [self searchFromLastPages:currentBookPath index:nil];
if (object) {
newDic = object;
}
}
int index = 0;
id objectS = [self searchFromRecentItems:currentBookPath index:&index];
if (objectS) {
[newRecentItems removeObjectAtIndex:index];
newDic = objectS;
}
[newRecentItems insertObject:newDic atIndex:0];
[defaults setObject:newRecentItems forKey:@"RecentItems"];
} else {
[defaults removeObjectForKey:@"RecentItems"];
}
[self setOpenRecentMenu];
NSMenu *menu=[openRecentMenuItem submenu];
[[menu itemAtIndex:0] setState:NSOnState];
[[menu itemAtIndex:0] setEnabled:NO];
[defaults synchronize];
imageLoader = newImageLoader;
completeMutableArray = [[imageLoader pathArray] retain];
sortMode = 0;
if ([currentBookSetting objectForKey:@"sortMode"]) {
sortMode = [[currentBookSetting objectForKey:@"sortMode"] intValue];
} else {
sortMode = (int)[defaults integerForKey:@"SortMode"];
}
if (sortMode!=0) {
[self setSortMode:sortMode page:-1];
}
if (fromFileName) {
page = (int)[completeMutableArray indexOfObject:fromFileName];
[fromFileName release];
}
if (last) {
int temp = (int)[completeMutableArray count];
temp--;
if ([completeMutableArray count] > 1) {
temp--;
[imageMutableArray addObject:[self loadImage:temp]];
temp++;
[imageMutableArray addObject:[self loadImage:temp]];
if ([self isSmallImage:[imageMutableArray objectAtIndex:0] page:temp] == NO){
[imageMutableArray removeObjectAtIndex:0];
temp++;
}
temp--;
} else {
[imageMutableArray addObject:[self loadImage:temp]];
}
nowPage = temp;
} else {
if (page >= [completeMutableArray count]) {
page = 0;
}
nowPage = page;
if ([completeMutableArray count] > page) {
[imageMutableArray addObject:[self loadImage:page]];
page++;
if ([completeMutableArray count] > page) {
[imageMutableArray addObject:[self loadImage:page]];
}
}
}
readMode = (int)[defaults integerForKey:@"ReadMode"];