-
Notifications
You must be signed in to change notification settings - Fork 5
/
bookSearchForm.pas
executable file
·1378 lines (1208 loc) · 50 KB
/
bookSearchForm.pas
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
unit bookSearchForm;
{$I videlibrilanguageconfig.inc}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
CheckLst, StdCtrls,bookListView, ComCtrls, Menus,librarySearcher,booklistreader,TreeListView,math,
librarySearcherAccess,multipagetemplate,applicationformconfig, commoninterface, coverLoaderAccess;
type
{ TbookSearchFrm }
TbookSearchFrm = class(TVideLibriForm)
detailPanel: TPanel;
holdingsPanel: TPanel;
bookListPanel2: TPanel;
searchLocationRegion: TComboBox;
menuCopyValue: TMenuItem;
menuCopyRow: TMenuItem;
PopupMenu1: TPopupMenu;
holdingsSplitter: TSplitter;
Splitter2: TSplitter;
Splitter4: TSplitter;
startAutoSearchButton: TButton;
Label12: TLabel;
LabelOrder: TLabel;
LabelOrderFor: TLabel;
LabelSaveTo: TLabel;
saveToAccountMenu: TPopupMenu;
orderForAccountMenu: TPopupMenu;
SearchParamsBox: TScrollBox;
startSearch: TButton;
displayImage: TCheckBox;
displayInternalProperties: TCheckBox;
detailPanelHolder: TPanel;
Image1: TImage;
Panel1: TPanel;
searchLocation: TComboBox;
searchSelectionList: TCheckListBox;
Label1: TLabel;
optionPanel: TPanel;
bookListPanel: TPanel;
Splitter1: TSplitter;
Splitter3: TSplitter;
StatusBar1: TStatusBar;
autoSearchContinueTimer: TTimer;
procedure autoSearchContinueTimerTimer(Sender: TObject);
procedure bookListSelect({%H-}sender: TObject; item: TTreeListItem);
procedure bookListVScrollBarChange(Sender: TObject);
procedure detailPanelHolderClick(Sender: TObject);
procedure menuCopyRowClick(Sender: TObject);
procedure menuCopyValueClick(Sender: TObject);
procedure optionPanelClick(Sender: TObject);
procedure Panel1Click(Sender: TObject);
procedure searchLocationRegionSelect(Sender: TObject);
procedure startAutoSearchButtonClick(Sender: TObject);
procedure detaillistClickAtRecordItem({%H-}sender: TObject; recorditem: TTreeListRecordItem);
procedure detaillistCustomRecordItemDraw(sender: TObject; {%H-}eventTyp_cdet: TCustomDrawEventTyp; recordItem: TTreeListRecordItem;
var {%H-}defaultDraw: Boolean);
procedure detaillistMouseMove(Sender: TObject; {%H-}Shift: TShiftState; X, Y: Integer);
procedure searcherAccessConnected(Sender: TObject);
procedure displayImageChange(Sender: TObject);
procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
procedure FormDeactivate(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure Label12Click(Sender: TObject);
procedure LabelOrderClick(Sender: TObject);
procedure LabelOrderForClick(Sender: TObject);
procedure LabelSaveToClick(Sender: TObject);
procedure searcherAccessOrderComplete(sender: TObject; book: TBook);
procedure searcherAccessPendingMessageCompleted(Sender: TObject);
procedure searcherAccessTakePendingMessage({%H-}sender: TObject; book: TBook; pendingMessage: TPendingMessage);
procedure searchTitleChange(Sender: TObject);
procedure startSearchClick(Sender: TObject);
procedure displayInternalPropertiesChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure searcherAccessDetailsComplete(sender: TObject; book: TBook);
procedure searcherAccessException(Sender: TObject);
procedure searcherAccessSearchComplete(sender: TObject; firstPage, nextPageAvailable: boolean);
procedure searchLocationSelect(Sender: TObject);
procedure searchSelectionListClickCheck(Sender: TObject);
private
function GetDigibibTemplate: TMultiPageTemplate;
private
{ private declarations }
locations: TSearchableLocations;
selectedLibrariesPerLocation: TStringList;
autoSearchPhase: (aspConnecting, aspConnected, aspSearching, aspSearched, aspSearchingDetails, aspSearchedDetails);
autoSearchDetailCount: integer;
procedure makeSearcherAccess(connectNow: boolean = true);
function currentLocationRegionConfig: string;
property digibibtemplate: TMultiPageTemplate read GetDigibibTemplate;
public
{ public declarations }
bookList: TBookListView;
detaillist: TTreeListView;
detaillistLastClickedRecordItem: TTreeListRecordItem;
holdings: TBookListView;
searcherAccess: TLibrarySearcherAccess;
coverLoader: TCoverLoaderAccess;
newSearcherAccess: TLibrarySearcherAccess;
nextPageAvailable: boolean;
displayedBook: TBook;
researchedBook: TBook;
procedure bookListHoldingsSelect({%H-}sender: TObject; item: TTreeListItem);
procedure detaillistMouseDown(Sender: TObject; {%H-}Button: TMouseButton; {%H-}Shift: TShiftState; X, Y: Integer);
function displayDetails(book: TBook=nil): longint; //0: no details, 1: detail, no image, 2: everything
function displayCover(book: TBook): boolean; //false: no cover, true: displayed cover
function cloneDisplayedBook: TBook;
procedure selectBookToReSearch(book: TBook);
procedure loadDefaults;
procedure saveDefaults;
protected
searchParams: TFormParams;
searchLabels: array of TLabel;
searchControls: array of TComboBox;
procedure createSearchControls;
function findSearchControl(const n: string): TComboBox;
public
saveToDefaultAccountID, orderForDefaultAccountID: string;
procedure changeDefaultSaveToAccount(sender:tobject);
procedure changeDefaultOrderForAccount(sender:tobject);
end;
var
bookSearchFrm: TbookSearchFrm;
const SB_PANEL_FOUND_COUNT=1;
SB_PANEL_SEARCH_STATUS=0;
implementation
uses applicationconfig,applicationdesktopconfig, libraryParser,simplexmlparser,bbdebugtools,bookWatchMain,bbutils,LCLType,libraryAccess,LCLIntf,strutils,Clipbrd,bookproperties,xquery__regex,commoninterfacehelpers,androidutils;
{ TbookSearchFrm }
resourcestring
rsPropertyName = 'Eigenschaftsname';
rsValue = 'Wert';
rsWait = 'Warte...';
rsSearchException = 'Es ist ein Fehler aufgetreten';
rsSearching = 'Suche Medien...';
rsBytesHidden = '<%s Bytes ausgeblendet>';
rsPropertiesNormal = 'normale Eigenschaften';
rsPropertiesInternal = 'interne Eigenschaften';
rsPropertiesEmpty = 'leere Eigenschaften';
rsBookPropertyFirstTime = 'Erstes Vorkommen';
rsBookPropertyLastTime = 'Letztes Vorkommen';
rsRequestOrder = 'Vormerken/Bestellen';
rsSearchingDetails = 'Suche Details für dieses Medium...';
rsLoadingNextPage = 'Lade nächste Seite...';
rsSearchComplete = 'Suche abgeschlossen';
rsSearchingCover = 'Suche Titelbild...';
rsSearchPartiallyComplete = 'Suche abgeschlossen (mehr Ergebnisse verfügbar)';
rsExistsOverrideConfirm = 'Das Medium existiert bereits als "%s", soll es mit "%s" überschrieben werden?';
rsOverrideConfirm = 'Soll das markierte Medium "%s" mit "%s" überschrieben werden?';
rsNoHoldingSelected = 'Es wurde nicht ausgewählt, welches Exemplar bestellt werden soll. (in der unteren Liste)';
rsOrderConfirm = 'Soll "%s" bestellt werden?';
rsOrderComplete = 'Das Buch "%s" wurde ohne Fehler vorgemerkt. %s';
rsCount = '%s Treffer';
rsCountSelected = '%D / %D Treffer';
rsFor = 'für';
rsIn = 'in';
procedure TbookSearchFrm.FormCreate(Sender: TObject);
var
i: Integer;
begin
selectedLibrariesPerLocation:= TStringList.Create;
loadDefaults;
bookList:=TBookListView.create(self,false);
for i := 0 to high(defaultBookListViewSearchColumns) do
booklist.addColumn(defaultBookListViewSearchColumns[i]);
bookList.Parent:=bookListPanel2;
booklist.deserializeColumnWidths(userConfig.ReadString('BookSearcher','ListColumnWidths','200,200,50,75'));
booklist.OnSelect:=@bookListSelect;
bookList.OnVScrollBarChange:=@bookListVScrollBarChange;
searcherAccess := nil;
coverLoader:=TCoverLoaderAccess.create;
coverloader.OnImageReceived := @displayImageChange;
detaillist:=TTreeListView.Create(self);
detaillist.Parent:=detailPanel;
detaillist.align:=alClient;
detaillist.columns.Clear;
detaillist.PopupMenu := PopupMenu1;
with detaillist.columns.Add do begin
text:=rsPropertyName;
width:=170;
end;
with detaillist.columns.Add do begin
text:=rsValue;
width:=400;
end;
detaillist.OnCustomRecordItemDraw:=@detaillistCustomRecordItemDraw;
detaillist.OnClickAtRecordItem:=@detaillistClickAtRecordItem;
detaillist.OnMouseMove:=@detaillistMouseMove;
detaillist.OnMouseDown:=@detaillistMouseDown;
holdings := TBookListView.create(self, false);
holdings.Parent := holdingsPanel;
holdings.align:=alClient;
holdings.OnSelect:=@bookListHoldingsSelect;
holdings.PopupMenu := PopupMenu1;
holdings.OnCustomRecordItemDraw:=@detaillistCustomRecordItemDraw;
holdings.OnClickAtRecordItem:=@detaillistClickAtRecordItem;
holdings.OnMouseMove:=@detaillistMouseMove;
holdings.OnMouseDown:=@detaillistMouseDown;
Image1.Width:=0;
if debugMode then begin
startAutoSearchButton.Visible := true;
end;
createSearchControls;
end;
procedure TbookSearchFrm.startSearchClick(Sender: TObject);
procedure addCbHistory(cb: TComboBox);
var
temp: TCaption;
maxCount: LongInt;
begin
if (cb.text='') or (cb.Items.IndexOf(cb.Text)>=0) then exit;
temp := cb.Text;
cb.Items.Insert(0,temp);
maxCount := userConfig.ReadInteger('BookSearcher', 'HistoryMaxLength', 15);
while cb.Items.Count>maxCount do cb.Items.Delete(maxCount);
cb.Text := temp; //lines above sometimes erase text
end;
var i:longint;
begin
if Assigned(displayedBook) and not assigned(displayedBook.owningAccount) then
displayedBook:=nil; //do not nil it for borrowed books since ít might be loading the cover in the background and should show it once it is loaded
nextPageAvailable:=false;
if newSearcherAccess <> nil then begin
if (searcherAccess <> nil) then begin
searcherAccess.freeAsync;
end;
searcherAccess := newSearcherAccess;
newSearcherAccess := nil;
end;
i := locations.locations.IndexOf(searchLocation.Text);
if i = -1 then begin i := 0; if locations.locations.Count = 0 then raise exception.Create('No search templates'); end;
screen.Cursor:=crHourGlass;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsWait;
searcherAccess.prepareNewSearchWithoutDisconnect;
if searcherAccess.searcher = nil then exit;
//thread pending now, no need to use any locking
for i := 0 to high(searchControls) do begin
if searchParams.inputs[i] is TFormSelect then begin
if (searchControls[i].ItemIndex >= 0) and (searchControls[i].ItemIndex < length(TFormSelect(searchParams.inputs[i]).optionValues)) then
searcherAccess.searcher.SearchOptions.setProperty(searchParams.inputs[i].name, TFormSelect(searchParams.inputs[i]).optionValues[searchControls[i].ItemIndex]);
end else
searcherAccess.searcher.SearchOptions.setProperty(searchParams.inputs[i].name, searchControls[i].Text);
addCbHistory(searchControls[i])
end;
searcherAccess.searchAsync;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearching;
end;
procedure TbookSearchFrm.displayInternalPropertiesChange(Sender: TObject);
begin
displayDetails(nil);
end;
procedure TbookSearchFrm.bookListSelect(sender: TObject; item: TTreeListItem);
var book: tbook;
begin
if (item=nil) or not (item.Selected) then exit;
if searcherAccess = nil then exit;
book:=tbook(item.data.obj);
if displayDetails() < 1 then begin
searcherAccess.detailsAsyncSave(book);
Screen.Cursor:=crHourGlass;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearchingDetails;
end;
if (nextPageAvailable) and (item = bookList.Items[booklist.Items.Count - 1]) then begin
nextPageAvailable := false;
searcherAccess.searchNextAsync;
end;
end;
procedure TbookSearchFrm.autoSearchContinueTimerTimer(Sender: TObject);
var
i: Integer;
begin
// if searcherAccess.operationActive then exit;
case autoSearchPhase of
aspConnected: begin
autoSearchPhase:=aspSearching;
startSearch.Click;
exit;
end;
aspSearched: begin
autoSearchDetailCount := min(3, bookList.VisibleRowCount);
end;
aspSearchedDetails: begin
autoSearchDetailCount -= 1;
end
else exit;
end;
if autoSearchDetailCount <= 0 then begin
if searchSelectionList.Checked[searchSelectionList.Count-1] then begin
if searchLocation.ItemIndex = searchLocation.Items.Count - 1 then begin
autoSearchContinueTimer.Enabled := false;
exit;
end;
searchLocation.ItemIndex := searchLocation.ItemIndex + 1;
searchLocationSelect(searchLocation);
for i := 0 to searchSelectionList.Count - 1 do
searchSelectionList.Checked[i] := false;
searchSelectionList.Checked[0] := true;
end else begin
for i := 0 to searchSelectionList.Count - 2 do
if searchSelectionList.Checked[i] then begin
searchSelectionList.Checked[i] := false;
searchSelectionList.Checked[i + 1] := true;
break;
end;
end;
autoSearchPhase:=aspConnecting;
searchSelectionListClickCheck(searchSelectionList);
exit;
end;
;
// if bookList.Selected = nil then bookList.Selected := ;
autoSearchPhase:=aspSearchingDetails;
bookList.Selected := bookList.Items[bookList.Items.IndexOf(bookList.Selected)+1];
end;
procedure TbookSearchFrm.bookListVScrollBarChange(Sender: TObject);
begin
if nextPageAvailable
and (bookList.VisibleRowCount > bookList.Items.Count - bookList.TopItemVisualIndex)
and (searcherAccess<>nil)
then begin
nextPageAvailable := false;
searcherAccess.searchNextAsync;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsLoadingNextPage;
end;
end;
procedure TbookSearchFrm.detailPanelHolderClick(Sender: TObject);
begin
end;
procedure TbookSearchFrm.menuCopyRowClick(Sender: TObject);
var
opener: TComponent;
list: TTreeListView;
v: String;
item: TTreeListItem;
i: Integer;
begin
opener := ((Sender as TMenuItem).GetParentMenu as TPopupMenu).PopupComponent;
if opener = holdings then list := holdings
else list := detaillist;
item := list.selected;
if item = nil then exit;
v := item.Text;
if list = detaillist then v := v + ': '+ item.RecordItemsText[1]
else for i := 1 to item.RecordItems.Count - 1 do begin
if (i = item.RecordItems.Count - 1) and (item.RecordItemsText[i] = '') then continue; //is there a hidden column?
v := v + '|'+ item.RecordItemsText[i];
end;
Clipboard.AsText := v;
end;
procedure TbookSearchFrm.menuCopyValueClick(Sender: TObject);
begin
if detaillistLastClickedRecordItem = nil then exit;
Clipboard.AsText := detaillistLastClickedRecordItem.Text;
end;
procedure TbookSearchFrm.optionPanelClick(Sender: TObject);
begin
end;
procedure TbookSearchFrm.Panel1Click(Sender: TObject);
begin
end;
procedure TbookSearchFrm.searchLocationRegionSelect(Sender: TObject);
var
i: Integer;
locs: TStringList;
temp: String;
begin
i := locations.regions.IndexOf(searchLocationRegion.Text);
if i < 0 then exit;
locs := locations.regions.Objects[i] as TStringList;
searchLocation.Items.Clear;
for i := 0 to locs.count - 1 do
searchLocation.Items.add(locs[i]);
if locs.count = 0 then exit;
temp := userConfig.ReadString('BookSearcher', currentLocationRegionConfig, '');
if locs.IndexOf(temp) >= 0 then searchLocation.Text := temp
else searchLocation.text := locs[0];
searchLocationSelect(searchLocation);
end;
procedure TbookSearchFrm.startAutoSearchButtonClick(Sender: TObject);
var
i: Integer;
begin
autoSearchContinueTimer.Enabled:=true;
// searchLocation.ItemIndex := 1;
// searchLocationSelect(searchLocation);
for i := 0 to searchSelectionList.Count - 1 do
searchSelectionList.Checked[i] := false;
searchSelectionList.Checked[0] := true;
searchSelectionListClickCheck(searchSelectionList);
end;
procedure TbookSearchFrm.detaillistClickAtRecordItem(sender: TObject; recorditem: TTreeListRecordItem);
var
i: SizeInt;
temp: String;
begin
if striContains(recordItem.Text, 'http://') or striContains(recordItem.Text, 'https://') then begin
i := striIndexOf(recordItem.Text, 'http://');
if i <= 0 then i := striIndexOf(recordItem.Text, 'https://');
temp := strCopyFrom(recorditem.Text, i);
if strContains(temp, ' ') then delete(temp, strIndexOf(temp, ' '), length(temp));
openURL(temp);
end;
end;
procedure TbookSearchFrm.detaillistCustomRecordItemDraw(sender: TObject; eventTyp_cdet: TCustomDrawEventTyp;
recordItem: TTreeListRecordItem; var defaultDraw: Boolean);
begin
if strContains(recordItem.Text, 'http://') or strContains(recordItem.Text, 'https://') then ttreelistview(sender).Canvas.Font.Color:=clBlue
else ttreelistview(sender).Canvas.Font.Color:=clBlack;
end;
procedure TbookSearchFrm.detaillistMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
tlv: TTreeListView;
recordItem: TTreeListRecordItem;
begin
tlv := TTreeListView(sender);
recordItem := tlv.GetRecordItemAtPos(x,y);
if (recorditem <> nil) and (strContains(recordItem.Text, 'http://') or strContains(recordItem.Text, 'https://')) then
tlv.Cursor:=crHandPoint
else
tlv.Cursor:=crDefault;
end;
procedure TbookSearchFrm.searcherAccessConnected(Sender: TObject);
begin
if sender <> newSearcherAccess then exit;
if newSearcherAccess.searcher = nil then exit;
createSearchControls;
autoSearchPhase:=aspConnected;
end;
procedure TbookSearchFrm.displayImageChange(Sender: TObject);
begin
if displayCover(displayedBook) then begin
if StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text=rsSearchingCover then begin
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:='';
screen.Cursor:=crDefault;
end;
end;
end;
procedure TbookSearchFrm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
saveDefaults;
end;
procedure TbookSearchFrm.FormDeactivate(Sender: TObject);
begin
end;
procedure TbookSearchFrm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_RETURN then startSearch.Click
else if key = VK_ESCAPE then close
else exit;
key:=0;
end;
procedure TbookSearchFrm.Label12Click(Sender: TObject);
var temp, old:TBook;
acc: TCustomAccountAccess;
i: Integer;
begin
if displayedBook = nil then exit;
if accounts.Count = 0 then exit;
acc := accounts[0];
for i:=1 to accounts.Count-1 do
if accounts.Strings[i] = saveToDefaultAccountID then acc := accounts[i];
//if acc.isThreadRunning then begin ShowMessage('Während dem Aktualisieren können keine weiteren Medien gespeichert werden.'); exit; end;
temp := cloneDisplayedBook;
temp.issueDate:=-2;
temp.dueDate:=-2;
if (mainForm.BookList.SelectedBook <> nil) and (mainForm.BookList.SelectedBook.owningAccount = acc) then begin
old := mainForm.BookList.SelectedBook;
if (old.author = temp.author) or (old.title = temp.title) or
striBeginsWith(temp.author,old.author) or striBeginsWith(temp.title, old.title) then
if confirm(Format(rsExistsOverrideConfirm, [old.toSimpleString(), temp.toSimpleString()])) then begin
EnterCriticalsection(updateThreadConfig.libraryAccessSection);
old.author:=temp.author; //don't copy id
old.title:=temp.title;
old.year:=temp.year;
old.isbn:=temp.isbn;
old.assign(temp);
acc.saveBooks();
LeaveCriticalsection(updateThreadConfig.libraryAccessSection);
mainForm.RefreshListView;
exit;
end;
if researchedBook <> nil then
if confirm(Format(rsOverrideConfirm, [old.toSimpleString(), temp.toSimpleString()])) then begin
EnterCriticalsection(updateThreadConfig.libraryAccessSection);
old.author:=temp.author; //don't copy id
old.title:=temp.title;
old.year:=temp.year;
old.isbn:=temp.isbn;
old.assign(temp);
acc.saveBooks();
LeaveCriticalsection(updateThreadConfig.libraryAccessSection);
mainForm.RefreshListView;
researchedBook := nil;
exit;
end;
end;
EnterCriticalsection(updateThreadConfig.libraryAccessSection);
acc.books.old.add(temp);
acc.saveBooks();
LeaveCriticalsection(updateThreadConfig.libraryAccessSection);
mainForm.RefreshListView;
researchedBook := nil;
end;
function bookIsOrderable(book: TBook): boolean;
begin
result := (getProperty( 'orderable', book.additional) <> '') and (getProperty('orderable', book.additional) <> '0') and (getProperty('orderable', book.additional) <> 'false');
end;
procedure TbookSearchFrm.LabelOrderClick(Sender: TObject);
var
acc: TCustomAccountAccess;
i: Integer;
orderBook: TBook;
begin
if (displayedBook = nil) or (searcherAccess = nil) then exit;
if accounts.Count = 0 then exit;
orderBook := displayedBook;
if displayedBook.holdings <> nil then
if holdings.SelectedBook <> nil then orderBook := holdings.SelectedBook
else if not bookIsOrderable(orderBook) then begin
ShowMessage(rsNoHoldingSelected);
exit;
end;
acc := accounts[0];
for i:=1 to accounts.Count-1 do
if accounts.Strings[i] = orderForDefaultAccountID then acc := accounts[i];
//if acc.isThreadRunning then begin ShowMessage('Während dem Aktualisieren/Verlängern/Vormerken können keine weiteren Medien vorgemerkt werden.'); exit; end;
if not confirm(Format(rsOrderConfirm, [displayedBook.title])) then exit;
screen.Cursor:=crHourGlass;
searcherAccess.orderAsync(acc, orderBook);
end;
procedure TbookSearchFrm.LabelOrderForClick(Sender: TObject);
begin
orderForAccountMenu.PopUp();
end;
procedure TbookSearchFrm.LabelSaveToClick(Sender: TObject);
begin
saveToAccountMenu.PopUp;
end;
procedure TbookSearchFrm.searcherAccessOrderComplete(sender: TObject; book: TBook);
var
acc: TCustomAccountAccess;
temp: TBook;
begin
if sender <> searcherAccess then exit;
//see androidutils/bookSearchForm
searcherAccess.beginBookReading;
EnterCriticalSection(updateThreadConfig.libraryAccessSection);
acc := TCustomAccountAccess(book.owningAccount);
temp := book.clone; temp.status:=bsOrdered;
acc.books.current.add(temp);
temp := book.clone; temp.status:=bsOrdered;
acc.books.currentUpdate.add(temp); //cannot know which one is the correct one? one will be discarded?
acc.saveBooks();
LeaveCriticalSection(updateThreadConfig.libraryAccessSection);
searcherAccess.endBookReading;
if mainForm <> nil then mainForm.RefreshListView;
ShowMessage(format(rsOrderComplete, [book.toSimpleString(), LineEnding + LineEnding + book.statusStr]) );
screen.Cursor:=crDefault;
end;
procedure TbookSearchFrm.searcherAccessPendingMessageCompleted(Sender: TObject);
begin
screen.Cursor:=crDefault;
end;
procedure TbookSearchFrm.searcherAccessTakePendingMessage(sender: TObject; book: TBook; pendingMessage: TPendingMessage);
var
i: Integer;
begin
screen.Cursor:=crDefault;
case pendingMessage.kind of
pmkAlert: begin
ShowMessage(pendingMessage.caption);
if pendingMessage.callback <> '' then searcherAccess.completePendingMessage(book, pendingMessage, 0);
end;
pmkChoose: begin
i := InputList(pendingMessage.caption, pendingMessage.options);
screen.Cursor:=crHourGlass;
searcherAccess.completePendingMessage(book, pendingMessage, i);
end;
pmkConfirm: begin
searcherAccess.completePendingMessage(book, pendingMessage, ifthen(confirm(pendingMessage.caption), 1, 0));
end;
end;
end;
procedure TbookSearchFrm.searcherAccessSearchComplete(sender: TObject; firstPage, nextPageAvailable: boolean);
begin
if sender <> searcherAccess then exit;
if searcherAccess.searcher = nil then exit;
bookList.BeginUpdate;
if firstPage then bookList.Clear;
self.nextPageAvailable := nextPageAvailable;;
searcherAccess.beginResultReading;
bookList.addBookList(searcherAccess.searcher.SearchResult);
if (bookList.Items.Count = searcherAccess.searcher.SearchResultCount) or (searcherAccess.searcher.SearchResultCount = 0) then
StatusBar1.Panels[SB_PANEL_FOUND_COUNT].text:=Format(rsCount, [IntToStr(bookList.Items.Count)])
else
StatusBar1.Panels[SB_PANEL_FOUND_COUNT].text:=Format(rsCountSelected, [bookList.Items.Count, searcherAccess.searcher.SearchResultCount]
);
searcherAccess.endResultReading;
bookList.endupdate;
if (bookList.TopItemVisualIndex + bookList.VisibleRowCount > bookList.Items.Count) and (nextPageAvailable) then begin
searcherAccess.searchNextAsync;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsLoadingNextPage;
end else begin
if nextPageAvailable then
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearchPartiallyComplete
else
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearchComplete;
autoSearchPhase:=aspSearched;
end;
screen.Cursor:=crDefault;
end;
procedure TbookSearchFrm.searchTitleChange(Sender: TObject);
begin
end;
procedure TbookSearchFrm.FormDestroy(Sender: TObject);
begin
bookList.free;
detaillist.free;
searcherAccess.freeAsync;
coverLoader.shutdownAndFree;
newSearcherAccess.freeAsync;
//locations.searchTemplates.free;
locations.locations.Free;
locations.regions.Free;
selectedLibrariesPerLocation.free;
searchParams._ReleaseIfNonNil;
end;
procedure TbookSearchFrm.searcherAccessDetailsComplete(sender: TObject;
book: TBook);
begin
ignore(book);
if sender <> searcherAccess then exit;
if (displayDetails() < 2) and (displayImage.Checked) then begin
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearchingCover;
end else begin
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:='';
screen.Cursor:=crDefault;
autoSearchPhase:=aspSearchedDetails;
end;
end;
procedure TbookSearchFrm.searcherAccessException(Sender: TObject);
begin
if (sender <> searcherAccess) and (sender <> newSearcherAccess) then exit;
mainForm.delayedCall.Enabled:=true;
StatusBar1.Panels[SB_PANEL_SEARCH_STATUS].Text:=rsSearchException;
screen.Cursor:=crDefault;
end;
procedure TbookSearchFrm.searchLocationSelect(Sender: TObject);
var
i:longint;
loki: Integer;
libs: TStringList;
searchTarget: TSearchTarget;
begin
loki := locations.locations.IndexOf(searchLocation.Text);
libs := TStringList(locations.locations.Objects[loki]);
i := 0;
while i < libs.Count do begin
searchTarget := TSearchTarget(libs.Objects[i]);
if searchTarget.lib = nil then begin
searchTarget.lib := libraryManager.get(SearchTarget.id);
if searchTarget.lib = nil then begin
libs.Delete(i);
continue;
end;
libs[i] := searchTarget.lib.prettyName;
searchTarget.template := searchTarget.lib.template;
if strContains(searchTarget.template.name, 'digibib') and not strContains(searchTarget.template.name, 'digibib7') then begin
libs.AddObject(searchTarget.lib.prettyName + ' (digibib)', TSearchTarget.create(searchTarget.lib.prettyName+ ' (digibib)', searchTarget.lib, digibibtemplate));
end;
end;
inc(i);
end;
searchSelectionList.Items.Assign(libs);
for i:=1 to min(length(selectedLibrariesPerLocation.Values[searchLocation.Text]),
searchSelectionList.Items.count) do
searchSelectionList.Checked[i-1]:=selectedLibrariesPerLocation.Values[searchLocation.Text][i]='+';
makeSearcherAccess;
userConfig.WriteString('BookSearcher', currentLocationRegionConfig, searchLocation.Text);
end;
var gdigibibtemplate: TMultiPageTemplate;
procedure TbookSearchFrm.searchSelectionListClickCheck(Sender: TObject);
var s:string;
i:longint;
oldState: String;
last: LongInt;
disallowMultiselect: Boolean;
begin
oldState := selectedLibrariesPerLocation.Values[searchLocation.Text];
disallowMultiselect := false;
s:='';
last := 0;
for i:=0 to searchSelectionList.Items.count-1 do begin
if searchSelectionList.Checked[i] then begin
disallowMultiselect := disallowMultiselect or ((searchSelectionList.Items.Objects[i] as TSearchTarget).template <> gdigibibtemplate);
if disallowMultiselect and (i + 1 <= length(oldState)) and (oldState[i+1] = '+') then begin
last := i;
searchSelectionList.Checked[i] := false;
end;
end;
if searchSelectionList.Checked[i] then s+='+'
else s+='-';
end;
if (pos('+', s) = 0) and (last < searchSelectionList.Items.count) then begin
searchSelectionList.Checked[last] := true;
s[last+1] := '+';
end;
selectedLibrariesPerLocation.Values[searchLocation.Text]:=s;
makeSearcherAccess;
end;
function TbookSearchFrm.GetDigibibTemplate: TMultiPageTemplate;
begin
if gdigibibtemplate <> nil then exit(gdigibibtemplate);
{ searchTemplates := TStringList.Create;
searchTemplates.OwnsObjects := true;
searchTemplates.text := assetFileAsString('libraries/search/search.list');
for i := searchTemplates.count-1 downto 0 do begin
searchTemplates[i] := trim(searchTemplates[i]);
if searchTemplates[i] = '' then searchTemplates.Delete(i);
end;
for i :=0 to searchTemplates.count-1 do begin
searchTemplates.Objects[i] := TMultiPageTemplate.create();
TMultiPageTemplate(searchTemplates.Objects[i]).loadTemplateWithCallback(@assetFileAsString, StringReplace('libraries\search\templates\' +trim(searchTemplates[i])+'\','\',DirectorySeparator,[rfReplaceAll]),trim(searchTemplates[i]));
if searchTemplates[i] <> 'digibib' then begin
temp := TStringList.Create;
temp.OwnsObjects := true;
temp.AddObject(searchTemplates[i], TSearchTarget.create(searchTemplates[i], nil, TMultiPageTemplate(searchTemplates.Objects[i])));
locations.AddObject(searchTemplates[i], temp);
end else digibib := TMultiPageTemplate(searchTemplates.Objects[i]);
end;}
gdigibibtemplate := TMultiPageTemplate.create;
gdigibibtemplate.loadTemplateWithCallback(@assetFileAsString, StringReplace('libraries\search\templates\digibib\','\',DirectorySeparator,[rfReplaceAll]),'digibib');
result := gdigibibtemplate;
end;
procedure TbookSearchFrm.makeSearcherAccess(connectNow: boolean = true);
var
first: Boolean;
j: Integer;
i: Integer;
result: TLibrarySearcherAccess;
searchTarget: TSearchTarget;
begin
result:=TLibrarySearcherAccess.Create;
result.OnSearchPageComplete:=@searcherAccessSearchComplete;
result.OnDetailsComplete:=@searcherAccessDetailsComplete;
result.OnOrderComplete:=@searcherAccessOrderComplete;
result.OnTakePendingMessage:=@searcherAccessTakePendingMessage;
result.OnPendingMessageCompleted:=@searcherAccessPendingMessageCompleted;
result.OnException:=@searcherAccessException;
result.OnConnected:=@searcherAccessConnected;
if newSearcherAccess <> nil then newSearcherAccess.freeAsync;
newSearcherAccess := result;
i := locations.locations.IndexOf(searchLocation.Text);
if i = -1 then
exit;
first := true;
for j := 0 to searchSelectionList.Items.count - 1 do
if searchSelectionList.Checked[j] then begin
searchTarget := TSearchTarget((TStringList(locations.locations.Objects[i])).Objects[j]);
if searchTarget.lib = nil then continue;
if first then begin
result.newSearch( searchTarget.template );
result.searcher.clear;
first := false;
end;
result.searcher.addLibrary(searchTarget.lib);
end;
if first then begin
if TStringList(locations.locations.Objects[i]).count = 0 then exit;
searchTarget := TSearchTarget((TStringList(locations.locations.Objects[i])).Objects[j]);
if searchTarget.lib = nil then exit;
result.newSearch( searchTarget.template );
result.searcher.clear;
result.searcher.addLibrary(searchTarget.lib);
if searchSelectionList.Count > 0 then
searchSelectionList.Checked[0] := true;
end;
if connectNow then begin
result.connectAsync;
end;
createSearchControls; //from cache
end;
function TbookSearchFrm.currentLocationRegionConfig: string;
var
temp: TCaption;
i: Integer;
begin
temp := searchLocationRegion.Text;
result := '';
for i := 1 to length(temp) do if temp[i] in ['a'..'z','A'..'Z','0'..'9','-'] then result += temp[i];
result := 'default-location-' + result;
end;
function TbookSearchFrm.displayDetails(book: TBook): longint;
var intern, empty, normal: TTreeListItems; //item lists
procedure propAdd(n,v: string; important: boolean = false);
begin
if strEndsWith(n, '!') then begin
important := true;
delete(n, length(n), 1);
end;
if length(v)>1000 then begin
if important then v := copy(v, 1, 1000) + '..'
else v:=Format(rsBytesHidden, [IntToStr(length(v))]);
end;
if important and (v<>'') then
normal.add(n).RecordItems.Add(v)
else begin
if not displayInternalProperties.Checked then exit;
if v <> '' then begin
if intern=nil then intern:=detaillist.Items.Add(rsPropertiesInternal).SubItems;
intern.add(n).RecordItems.Add(v);
end else begin
if empty=nil then empty:=detaillist.Items.Add(rsPropertiesEmpty).SubItems;
empty.add(n).RecordItems.Add(v)
end;
end
end;
procedure propAddForce(n,v: string);
begin
propAdd(n,v, true);
end;
var i:longint;
tempStr: String;
j, orderableHolding: Integer;
showColumn, hadCover: Boolean;
tempBook: TBook;
begin
if book=nil then
if bookList.Selected=nil then book:=displayedBook
else book:=tbook(bookList.Selected.data.obj);
if (book=nil) then exit(2);
intern:=nil;
empty:=nil;
normal:=nil;
displayedBook:=book;
Result:=0;
if searcherAccess <> nil then searcherAccess.beginBookReading;
try
detaillist.BeginUpdate;
detaillist.items.clear;
if displayInternalProperties.Checked then normal := detaillist.Items.Add(rsPropertiesNormal).SubItems
else normal := detaillist.items;
for i := 0 to high(defaultDetailsProperties) do
propAddForce(getBookPropertyPretty(defaultDetailsProperties[i]), book.getProperty(defaultDetailsProperties[i]) );
if book.owningAccount<>nil then begin
propAddForce(rsBookPropertyIssueDate, DateToPrettyStr(book.issueDate));
propAddForce(rsBookPropertyLimitDate, DateToPrettyStr(book.dueDate));
propAddForce(rsBookPropertyStatus, BookStatusToStr(book,true));
propAdd(rsBookPropertyFirstTime, DateToPrettyStr(book.firstExistsDate));
propAdd(rsBookPropertyLastTime, DateToPrettyStr(book.lastExistsDate));
if book.renewCount > 0 then propAddForce(rsBookPropertyRenewCount, IntToStr(book.renewCount));
end;
for i:=0 to high(book.additional) do
propAdd(book.additional[i].name,book.additional[i].value);
detaillist.EndUpdate;
hadCover := displayCover(book);
if (getProperty('details-searched',book.additional) <> 'true') and (book.owningAccount = nil) then Result:=0
else if hadCover then result:=2
else result:=1;
tempStr := book.getPropertyAdditional('home-url');
if tempstr <> '' then propAddForce('Katalog-Link', tempStr);
tempStr := book.getPropertyAdditional('digibib-url');
if tempstr <> '' then propAddForce('Digibib-Link', tempStr);
tempStr := book.getPropertyAdditional('amazon-url');
if tempstr <> '' then propAddForce('Amazon-Link', tempStr);
//if (getProperty('buchhandel-url', book.additional) <> '') or (strContains(getProperty('image-real-url', book.additional), 'vlb.de')) then begin
//site:='http://www.buchhandel.de/default.aspx?strframe=titelsuche&caller=vlbPublic&func=DirectIsbnSearch&isbn='+displayedBook.getNormalizedISBN(true,13)+'&nSiteId=11';
//google: site:='http://www.google.de/search?q=%22'+urlencode(displayedBook.title)+'%22 %22'+urlencode(displayedBook.author)+'%22&ie=utf-8'
LabelOrder.Enabled:=bookIsOrderable(book);
if (book.holdings = nil) or (book.holdings.Count = 0) then begin
holdingsPanel.Visible := false;
holdingsSplitter.Visible := false;
LabelOrder.Caption := book.getPropertyAdditional('orderTitle', rsRequestOrder);
end else begin
holdings.BeginUpdate;