00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #include "camtypes.h"
00101 #include "sglbase.h"
00102 #include <io.h>
00103 #include <string.h>
00104 #include <strstrea.h>
00105 #include "pathnmex.h"
00106 #include "sgscanf.h"
00107
00108
00109
00110 #include "sginit.h"
00111 #include "sglcart.h"
00112 #include "sglib.h"
00113
00114
00115 #include "thumbmsg.h"
00116 #include "grnddib.h"
00117
00118
00119
00120 #include "sgliboil.h"
00121
00122
00123 #include "filedlgs.h"
00124
00125 #include "progress.h"
00126 #include "camelot.h"
00127
00128 #include "dragmgr.h"
00129
00130
00131
00132
00133
00134 #include "sgrmfile.h"
00135
00136
00137
00138 #include "registry.h"
00139 #include "product.h"
00140
00141 #include "inetop.h"
00142
00143
00144 CC_IMPLEMENT_DYNCREATE(LibraryGallery, SuperGallery)
00145
00146
00147 #define new CAM_DEBUG_NEW
00148
00149 using namespace InetUtils;
00150
00151
00152
00153
00154 BOOL LibraryGallery::AskAboutRemoving = FALSE;
00155
00156
00157 INT32 LibraryGallery::OffsetOfFirstGroupRemoved = -1;
00158
00159
00160 BOOL LibraryGallery::FirstGroupRemovedSelectionState = FALSE;
00161
00162
00163 KernelBitmap *LibraryGallery::TmpDraggingBitmap = NULL;
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 LibraryGallery::LibraryGallery()
00184 {
00185 if (!OpAddWebFolders::Init() || !OpAddWebLibrary::Init() || !OpThumbDownload::Init())
00186 {
00187 ERROR3("Failed to init web operations");
00188 }
00189
00190
00191
00192
00193
00194 bThumbDownloading = TRUE;
00195 m_bDiscardWebFolders = FALSE;
00196 }
00197
00198 LibraryGallery::~LibraryGallery()
00199 {
00200 TRACEUSER( "Richard", _T("~LibraryGallery called\n"));
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 MsgResult LibraryGallery::Message(Msg* Message)
00231 {
00232
00233
00234 if (DisplayTree == NULL)
00235 return(SuperGallery::Message(Message));
00236
00237 if (IS_OUR_DIALOG_MSG(Message))
00238 {
00239 DialogMsg* Msg = (DialogMsg*)Message;
00240
00241 switch (Msg->DlgMsg)
00242 {
00243 case DIM_LFT_BN_CLICKED:
00244 switch (Msg->GadgetID)
00245 {
00246 case _R(IDC_LIBGAL_REMOVE):
00247 RemoveSelectedLibraries(TRUE);
00248 UpdateGRMFile();
00249 break;
00250
00251 case _R(IDC_LIBGAL_WEB_CLIPART):
00252 case _R(IDC_LIBGAL_WEB_FILLS):
00253 case _R(IDC_LIBGAL_WEB_FONTS):
00254 OnGetButtonClicked();
00255 break;
00256 case _R(IDC_LIBGAL_STOP_LOADING):
00257 SuspendThumbnailDownloading();
00258 break;
00259
00260 }
00261 }
00262 }
00263
00264 return SuperGallery::Message(Message);
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 BOOL LibraryGallery::CanSearchKeywords(void)
00282 {
00283 return SuperGallery::CanSearchKeywords();
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 SGDisplayGroup *LibraryGallery::AddLibraryGroup(Library *LibraryToDisplay, INT32 NumItems)
00302 {
00303 return SuperGallery::AddLibraryGroup(LibraryToDisplay, NumItems);
00304 }
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 void LibraryGallery::SelectionHasChanged(void)
00320 {
00321
00322 EnableGadget(_R(IDC_GALLERY_MENU), TRUE);
00323 EnableGadget(_R(IDC_LIBGAL_BROWSE), TRUE);
00324
00325
00326 INT32 Count = DisplayTree->GetSelectedGroupCount();
00327 EnableGadget(_R(IDC_LIBGAL_REMOVE), (Count > 0));
00328 EnableGadget(_R(IDC_LIBGAL_STOP_LOADING), !m_lstPendingThumbs.empty());
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 void LibraryGallery::DoShadeGallery(BOOL ShadeIt)
00344 {
00345
00346 LibraryGallery::SelectionHasChanged();
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 BOOL LibraryGallery::PreCreate(void)
00372 {
00373 return SuperGallery::PreCreate();
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395 BOOL LibraryGallery::ApplyAction(SGActionType Action)
00396 {
00397 return SuperGallery::ApplyAction(Action);
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423 BOOL LibraryGallery::AddNewLibrary(PathName *LibPath, BOOL WipeOld, SGLibType LibType, BOOL Update)
00424 {
00425
00426
00427
00428 ERROR3IF(DisplayTree==NULL, "No display tree!");
00429 if(DisplayTree == NULL) return FALSE;
00430
00431 if(LibPath == NULL)
00432 {
00433 ERROR3("LibraryGallery::AddNewLibrary given null LibPath");
00434 return FALSE;
00435 }
00436
00437 if(WipeOld)
00438 {
00439
00440 OpenLibFiles.DeleteAll();
00441 LibraryGallery::SelectionHasChanged();
00442 }
00443
00444
00445 LibraryFile *LibFile = new LibraryFile;
00446 if (LibFile != NULL)
00447 {
00448
00449
00450
00451 if(!LibPath->IsValid())
00452 {
00453 ERROR3("LibraryGallery::AddNewLibrary given an invalid default library path");
00454 delete LibFile;
00455 InvalidateCachedFormat();
00456 ReformatAndRedrawIfNecessary();
00457 return FALSE;
00458 }
00459
00460 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
00461 BeginSlowJob(-1, FALSE, &SlowJob);
00462
00463 InvalidateCachedFormat();
00464
00465
00466 if (!LibFile->Init(this, LibPath, LibType, Update, FALSE))
00467 {
00468
00469 TRACEUSER( "Richard", _T("Problems with this new library... -> LibFile::Init returned false\n"));
00470 delete LibFile;
00471 EndSlowJob();
00472
00473 ReformatAndRedrawIfNecessary();
00474 return FALSE;
00475 }
00476 else
00477 {
00478 SortOutGroupsAfterLibraryAdd(LibFile, Update);
00479 }
00480
00481 EndSlowJob();
00482 }
00483
00484
00485 InvalidateCachedFormat();
00486 ReformatAndRedrawIfNecessary();
00487 return TRUE;
00488 }
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 BOOL LibraryGallery::SortOutGroupsAfterLibraryAdd(LibraryFile *LibFile, BOOL Update)
00512 {
00513
00514
00515 BOOL AddedLibFileToOpenLibList = FALSE;
00516
00517 if(Update && LibraryGallery::OffsetOfFirstGroupRemoved > -1 && GetDisplayTree() != NULL)
00518 {
00519
00520
00521
00522 SGLibGroup *LastGroup = (SGLibGroup *)GetDisplayTree()->GetChild();
00523 if(LastGroup != NULL)
00524 {
00525 while(LastGroup->GetNext() != NULL)
00526 LastGroup = (SGLibGroup *)LastGroup->GetNext();
00527
00528 LastGroup->SetSelected(LibraryGallery::FirstGroupRemovedSelectionState);
00529
00530
00531 INT32 GroupCount = 0;
00532 SGLibGroup *Group = (SGLibGroup *)GetDisplayTree()->GetChild();
00533 while(Group != NULL && GroupCount < LibraryGallery::OffsetOfFirstGroupRemoved)
00534 {
00535 Group = (SGLibGroup *)Group->GetNext();
00536 GroupCount ++;
00537 }
00538
00539
00540 if(Group != NULL && Group->GetNext() != NULL)
00541 {
00542 Group->MoveBefore(LastGroup);
00543 OpenLibFiles.InsertBefore((LISTPOS)LibraryGallery::OffsetOfFirstGroupRemoved, LibFile);
00544 AddedLibFileToOpenLibList = TRUE;
00545 }
00546 }
00547 }
00548
00549
00550 if(!AddedLibFileToOpenLibList)
00551 OpenLibFiles.AddTail(LibFile);
00552
00553
00554 LibFile->DoScrollRedraw();
00555
00556 UpdateGRMFile();
00557
00558 return TRUE;
00559 }
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 SGDisplayItem *LibraryGallery::AddLibraryItem(SGDisplayGroup *LibraryGroup, Library *ParentLib, LibraryIndex ItemIndex, BOOL bNew)
00590 {
00591 return SuperGallery::AddLibraryItem(LibraryGroup, ParentLib, ItemIndex, bNew);
00592 }
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 void LibraryGallery::HandleDragStart(DragMessage *DragMsg)
00614 {
00615 SuperGallery::HandleDragStart(DragMsg);
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 SGDisplayItem *LibraryGallery::CopyDisplayItem(SGDisplayItem *SourceItem,
00658 SGDisplayGroup *DestGroup, SGDisplayItem *TargetPosition)
00659 {
00660 return SuperGallery::CopyDisplayItem(SourceItem, DestGroup, TargetPosition);
00661 }
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 BOOL LibraryGallery::BrowseClicked(void)
00675 {
00676 return FALSE;
00677 }
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696 BOOL LibraryGallery::BrowseClicked(String_256 *DefaultPath, SGLibType Type, INT32 Message)
00697 {
00698 BOOL Updated = FALSE;
00699 PathName ThePath(*DefaultPath);
00700
00701
00702 if(SGLibOil::GetLibPath(this, &ThePath, CanCreateIndexes(), Type, &Updated))
00703 {
00704 if(!ThePath.IsValid())
00705 {
00706 String_256 Tmp(ThePath.GetPath());
00707 ERROR3_PF(("LibraryGallery::BrowseClicked GetLibPath returned an invalid pathname - '%s'", (TCHAR *)Tmp));
00708 }
00709 else
00710 {
00711
00712 INT32 ButtonPressed = 2;
00713
00714 if(LibraryGroupsInGallery() > 0 && LibraryGallery::AskAboutRemoving)
00715 {
00716
00717 ButtonPressed = InformMessage(Message, _R(IDS_REMOVE), _R(IDS_KEEP), _R(IDS_CANCEL));
00718 Error::ClearError();
00719
00720 if(ButtonPressed == 3)
00721 return FALSE;
00722 }
00723
00724
00725 if(AddNewLibrary(&ThePath, ButtonPressed == 1, Type, Updated))
00726 {
00727
00728 *DefaultPath = ThePath.GetPath();
00729 }
00730
00731
00732 SortGallery();
00733
00734 ReformatAndRedrawIfNecessary();
00735
00736 return TRUE;
00737 }
00738 }
00739 return FALSE;
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 BOOL LibraryGallery::CanCreateIndexes(void)
00757 {
00758 return FALSE;
00759 }
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779 BOOL LibraryGallery::GetDefaults(String_256 *DefaultIndex, String_256 *IndexDesc, SGLibType *Type)
00780 {
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811 return FALSE;
00812 }
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 BOOL LibraryGallery::GetLibraryDirectoryName(String_256 *LibDirName)
00831 {
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852 return FALSE;
00853 }
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870 BOOL LibraryGallery::CheckForIndexMatch(StringBase *Txt)
00871 {
00872
00873
00874
00875
00876
00877
00878
00879
00880 return FALSE;
00881 }
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895 BOOL LibraryGallery::GetQuietStatus(void)
00896 {
00897 return FALSE;
00898 }
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912 void LibraryGallery::SetQuietStatus(BOOL Status)
00913 {
00914 }
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934 BOOL LibraryGallery::ScanForLocation(SGLibType Type, StringBase *Result)
00935 {
00936 return FALSE;
00937 }
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950 void LibraryGallery::SortGallery(void)
00951 {
00952
00953 return;
00954
00955
00956 SGSortKey TmpSortKeys[MaxSGSortKeys];
00957 for (INT32 i = 0; i < MaxSGSortKeys; i++)
00958 {
00959 TmpSortKeys[i] = SortKeys[i];
00960 SortKeys[i].SortKey = 0;
00961 SortKeys[i].Reversed = FALSE;
00962 }
00963 SortKeys[0].SortKey = 1;
00964
00965 ApplySortNow(TRUE);
00966
00967 for (i = 0; i < MaxSGSortKeys; i++)
00968 SortKeys[i] = TmpSortKeys[i];
00969
00970 }
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983 INT32 LibraryGallery::GetDisplayMode(void)
00984 {
00985
00986 return DisplayMode;
00987 }
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001 void LibraryGallery::RemoveSelectedLibraries(BOOL Warn)
01002 {
01003 BOOL FullRedrawNecessary = FALSE;
01004
01005 ERROR3IF(DisplayTree == NULL, "LibraryGallery::RemoveSelectedLibraries called with null display tree");
01006
01007 INT32 GroupCount = GetSelectedGroupCount();
01008
01009
01010
01011 if(GroupCount > 0)
01012 {
01013 INT32 ButtonPressed = 1;
01014
01015 if(Warn)
01016 ButtonPressed = InformMessage(_R(IDS_LIBRARY_CHECK_REMOVE), _R(IDS_REMOVE), _R(IDS_CANCEL));
01017
01018 if(ButtonPressed == 1)
01019 {
01020 SGDisplayGroup *Group = DisplayTree->FindNextSelectedGroup(NULL);
01021 SGDisplayGroup *NextGroup = NULL;
01022 BOOL DoingSlowJob = FALSE;
01023
01024 INT32 ActualCount = 0;
01025 if(GroupCount > 0)
01026 {
01027 String_64 SlowJob(_R(IDS_LIBRARY_REMOVING_FOLDERS));
01028 BeginSlowJob(GroupCount, FALSE, &SlowJob);
01029 DoingSlowJob = TRUE;
01030 }
01031
01032 while(Group != NULL)
01033 {
01034 NextGroup = DisplayTree->FindNextSelectedGroup(Group);
01035
01036 INT32 LibFileCount = OpenLibFiles.GetCount();
01037 BOOL DeletedGroup = FALSE;
01038
01039 if(LibFileCount > 0)
01040 {
01041
01042 INT32 LibFilesDeleted = 0;
01043 INT32 OriginalLibFileCount = LibFileCount;
01044
01045
01046 for(INT32 LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
01047 {
01048 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
01049
01050 INT32 LibCount = LibFile->Libraries.GetCount();
01051
01052 if(LibCount > 0)
01053 {
01054
01055 INT32 LibsDeleted = 0;
01056 INT32 OriginalLibCount = LibCount;
01057
01058
01059 for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
01060 {
01061 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
01062
01063 if(Lib->ParentGroup == Group)
01064 {
01065 if(Lib->ParentGroup->GetNext() == NULL)
01066 FullRedrawNecessary = TRUE;
01067
01068 Lib->ParentGroup->DestroySubtree(TRUE);
01069
01070 if (Lib->IsWebLibrary())
01071 {
01072 OpAddWebFolders::Success[Lib->GetType()] = FALSE;
01073
01074 DownloadCache::RemoveFile(Lib->ReturnIndexLocation()->GetPath());
01075 }
01076
01077
01078 delete(LibFile->Libraries.RemoveItem(Lib));
01079 LibsDeleted ++;
01080
01081 LibCount = LibFile->Libraries.GetCount();
01082 if(LibCount == 0)
01083 {
01084 delete(OpenLibFiles.RemoveItem(OpenLibFiles.FindItem(LibFileLoop)));
01085 LibFilesDeleted ++;
01086 }
01087
01088 DeletedGroup = TRUE;
01089 }
01090
01091 if(DeletedGroup)
01092 break;
01093 }
01094 }
01095 if(DeletedGroup)
01096 break;
01097 }
01098 }
01099
01100
01101 Group = NextGroup;
01102
01103
01104 if(DoingSlowJob)
01105 ContinueSlowJob(++ActualCount);
01106 }
01107
01108 if(DoingSlowJob)
01109 EndSlowJob();
01110
01111
01112 SelectionHasChanged();
01113
01114
01115 InvalidateCachedFormat();
01116 if(FullRedrawNecessary)
01117 ForceRedrawOfList();
01118 else
01119 ReformatAndRedrawIfNecessary();
01120 }
01121 }
01122 }
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143 INT32 LibraryGallery::RemoveSimilarLibraryGroups(PathName *FilesPath, String_256 *IndexFileName, BOOL RemoveFirstOne,
01144 BOOL Redraw, Library *DontKill)
01145 {
01146 ERROR3IF(FilesPath == NULL || IndexFileName == NULL, "LibraryGallery::RemoveSimilarLibraryGroups given null params");
01147 ERROR3IF(DisplayTree == NULL, "LibraryGallery::RemoveSimilarLibraryGroups called with null display tree");
01148
01149 INT32 RemovedGroups = 0;
01150
01151 BOOL FullRedrawNecessary = FALSE;
01152 INT32 GroupCount = LibraryGroupsInGallery();
01153
01154 LibraryGallery::OffsetOfFirstGroupRemoved = -1;
01155 INT32 OffsetCount = 0;
01156
01157 if(GroupCount > 0)
01158 {
01159
01160 String_256 UpperIndex(*IndexFileName);
01161 UpperIndex.toUpper();
01162 String_256 UpperFiles(FilesPath->GetPath());
01163 LibraryFile::TidyUpSubPath(&UpperFiles);
01164 UpperFiles.toUpper();
01165
01166 SGDisplayGroup *Group = (SGDisplayGroup *)DisplayTree->GetChild();
01167 SGDisplayGroup *NextGroup = NULL;
01168
01169
01170 while(Group != NULL)
01171 {
01172 NextGroup = (SGDisplayGroup *)Group->GetNext();
01173
01174 INT32 LibFileCount = OpenLibFiles.GetCount();
01175 BOOL DeletedGroup = FALSE;
01176
01177 if(LibFileCount > 0)
01178 {
01179
01180 INT32 LibFilesDeleted = 0;
01181 INT32 OriginalLibFileCount = LibFileCount;
01182
01183
01184 for(INT32 LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
01185 {
01186 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
01187 INT32 LibCount = LibFile->Libraries.GetCount();
01188
01189 if(LibCount > 0)
01190 {
01191
01192 INT32 LibsDeleted = 0;
01193 INT32 OriginalLibCount = LibCount;
01194
01195
01196 for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
01197 {
01198 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
01199
01200 if(Lib->ParentGroup == Group && Lib->SubLibPath != NULL && Lib->IndexFile != NULL && Lib != DontKill)
01201 {
01202 String_256 LibraryPath(Lib->SubLibPath->GetPath());
01203 String_256 LibraryIndex(Lib->IndexFile->GetFileName(TRUE));
01204 LibraryPath.toUpper();
01205 LibraryIndex.toUpper();
01206
01207
01208 if(UpperFiles == LibraryPath && UpperIndex == LibraryIndex)
01209 {
01210
01211 if(LibraryGallery::OffsetOfFirstGroupRemoved == -1)
01212 {
01213 LibraryGallery::OffsetOfFirstGroupRemoved = OffsetCount;
01214 LibraryGallery::FirstGroupRemovedSelectionState = Group->IsSelected();
01215 }
01216
01217 RemovedGroups++;
01218
01219 if(Lib->ParentGroup->GetNext() == NULL)
01220 FullRedrawNecessary = TRUE;
01221
01222 Lib->ParentGroup->DestroySubtree(TRUE);
01223
01224 delete(LibFile->Libraries.RemoveItem(Lib));
01225 LibsDeleted ++;
01226
01227 LibCount = LibFile->Libraries.GetCount();
01228 if(LibCount == 0)
01229 {
01230 delete(OpenLibFiles.RemoveItem(OpenLibFiles.FindItem(LibFileLoop)));
01231 LibFilesDeleted ++;
01232 }
01233
01234 DeletedGroup = TRUE;
01235 }
01236 }
01237
01238 if(DeletedGroup)
01239 break;
01240 }
01241 }
01242 if(DeletedGroup)
01243 break;
01244 }
01245 }
01246
01247
01248 Group = NextGroup;
01249 OffsetCount++;
01250 }
01251
01252
01253 SelectionHasChanged();
01254
01255
01256 if(Redraw)
01257 {
01258 InvalidateCachedFormat();
01259 if(FullRedrawNecessary)
01260 ForceRedrawOfList();
01261 else
01262 ReformatAndRedrawIfNecessary();
01263 }
01264 }
01265
01266 return RemovedGroups;
01267 }
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285 void LibraryGallery::WorkOutSectionName(String_256 *Section)
01286 {
01287 ERROR3IF(Section == NULL, "LibraryGallery::WorkOutSectionName given null section");
01288
01289 *Section = _R(IDS_SGLBASE_SECTION_NAME);
01290 }
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306 void LibraryGallery::WorkOutDescriptionSectionName(String_256 *Section)
01307 {
01308 ERROR3IF(Section == NULL, "LibraryGallery::WorkOutDescriptionSectionName given null section");
01309
01310 WorkOutSectionName(Section);
01311 *Section += String_256(_R(IDS_GRMFILE_DESCRIPTIONS));
01312 }
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329 void LibraryGallery::WorkOutLibraryTypeSectionName(String_256 *Section)
01330 {
01331 ERROR3IF(Section == NULL, "LibraryGallery::WorkOutLibraryTypeSectionName given null section");
01332
01333 WorkOutSectionName(Section);
01334 *Section += String_256(_R(IDS_GRMFILE_LIBRARYTYPES));
01335 }
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349 BOOL LibraryGallery::WipeGallerySettings(void)
01350 {
01351
01352 #ifdef SAVE_PREFS_TO_REGISTRY
01353
01354
01355 DeleteRegKeyAndSubKeys(hAppStateRegKey, PRODUCT_REGISTRYKEY_GALLERY);
01356
01357
01358
01359
01360 #endif
01361
01362
01363 LibSettings::NukeSettings();
01364
01365 return TRUE;
01366 }
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380 void LibraryGallery::UpdateGRMFile(void)
01381 {
01382 if(DisplayTree == NULL)
01383 ERROR3("LibraryGallery::UpdateGRMFile called with null display tree");
01384
01385 String_64 SlowJob(_R(IDS_LIBRARY_UPDATING_GRMF));
01386 BeginSlowJob(-1, TRUE, &SlowJob);
01387
01388 INT32 Pass = 0;
01389 String_256 SectionName;
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399 while(++Pass <= 3)
01400 {
01401 if(Pass == 1)
01402 WorkOutSectionName(&SectionName);
01403 else if (Pass == 2)
01404 WorkOutDescriptionSectionName(&SectionName);
01405 else if (Pass == 3)
01406 WorkOutLibraryTypeSectionName(&SectionName);
01407
01408 #ifdef SAVE_PREFS_TO_REGISTRY
01409
01410 String_256 KeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01411
01412 KeySectionName += SectionName;
01413
01414 SaveRegistryEntries Saver;
01415 BOOL StartedOk = Saver.StartSaving(&KeySectionName);
01416 ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01417
01418 if(!OpenLibFiles.IsEmpty() && StartedOk)
01419 {
01420 INT32 LibFileCount = OpenLibFiles.GetCount();
01421
01422 if(LibFileCount > 0)
01423 {
01424
01425 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
01426 {
01427 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
01428 INT32 LibCount = LibFile->Libraries.GetCount();
01429 if(LibCount > 0)
01430 {
01431
01432 for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
01433 {
01434 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
01435
01436
01437 if(Lib != NULL && Lib->IndexFile != NULL)
01438 {
01439 String_256 Line;
01440 if(Pass == 1)
01441 Line = Lib->IndexFile->GetPath();
01442 else if (Pass == 2)
01443 Lib->GetLibraryTitle(&Line);
01444 else if (Pass == 3)
01445 {
01446 INT32 libtype = Lib->Type;
01447 String_256 libstringtype;
01448 libstringtype._MakeMsg("#1%d",libtype);
01449 Line = libstringtype;
01450 }
01451
01452 if (Line.Length())
01453 {
01454 if (!Saver.SaveNextEntry(&Line))
01455 {
01456
01457 EndSlowJob();
01458 return;
01459 }
01460 }
01461 }
01462 }
01463 }
01464 }
01465 }
01466 }
01467
01468
01469 Saver.StopSaving();
01470 #else
01471 LibSettings::StartOutput(&SectionName);
01472 LibSettings::AddSection(&SectionName);
01473
01474 if(!OpenLibFiles.IsEmpty())
01475 {
01476 INT32 LibFileCount = OpenLibFiles.GetCount();
01477
01478 if(LibFileCount > 0)
01479 {
01480
01481 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
01482 {
01483 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
01484 INT32 LibCount = LibFile->Libraries.GetCount();
01485 if(LibCount > 0)
01486 {
01487
01488 for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
01489 {
01490 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
01491
01492
01493 if(Lib != NULL && Lib->IndexFile != NULL)
01494 {
01495 String_256 Line;
01496 if(Pass == 1)
01497 Line = Lib->IndexFile->GetPath();
01498 else if (Pass == 2)
01499 Lib->GetLibraryTitle(&Line);
01500 else if (Pass == 3)
01501 {
01502 INT32 libtype = Lib->Type;
01503 String_256 libstringtype;
01504 libstringtype._MakeMsg("#1%d",libtype);
01505 Line = libstringtype;
01506 }
01507
01508 if(!LibSettings::AddLine(&Line))
01509 {
01510
01511 EndSlowJob();
01512 return;
01513 }
01514 }
01515 }
01516 }
01517 }
01518 }
01519 }
01520 #endif
01521 }
01522 #ifdef SAVE_PREFS_TO_REGISTRY
01523 String_256 RootURLKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01524 RootURLKeySectionName += String_256(_R(IDS_ROOTURL));
01525 SaveRegistryEntries Saver;
01526 BOOL StartedOk = Saver.StartSaving(&RootURLKeySectionName);
01527 ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01528 Saver.SaveNextEntry(&Library::URLBase);
01529 #else
01530 String_256 strRootURLSectionName(_R(IDS_ROOTURL));
01531 LibSettings::StartOutput(&strRootURLSectionName);
01532 LibSettings::AddSection(&strRootURLSectionName);
01533 LibSettings::AddLine(&Library::URLBase);
01534 #endif
01535
01536 EndSlowJob();
01537 }
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557 BOOL LibraryGallery::AddLibraryGroups(SGLibType LibType, String_256 *DefaultLibraryPath)
01558 {
01559 TRACEUSER( "Matt", _T("AddLibraryGroups called in Base Class\n"));
01560
01561
01562 BOOL AddedGroups = FALSE;
01563
01564 if(AddGRMGroups(LibType))
01565 {
01566 AddedGroups = TRUE;
01567 }
01568 else
01569 {
01570
01571
01572
01573
01574
01575
01576
01577
01578 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
01579 BeginSlowJob(-1, FALSE, &SlowJob);
01580
01581
01582 LibraryFile *LibFile = new LibraryFile;
01583 if (LibFile != NULL)
01584 {
01585
01586
01587
01588 PathName ThePath(*DefaultLibraryPath);
01589 if (!LibFile->Init(this, &ThePath, LibType))
01590 {
01591
01592 delete LibFile;
01593 }
01594 else
01595 {
01596 OpenLibFiles.AddTail(LibFile);
01597 AddedGroups = TRUE;
01598
01599 }
01600 }
01601
01602 EndSlowJob();
01603
01604 }
01605
01606 return AddedGroups;
01607 }
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623 BOOL LibraryGallery::AddGRMGroups(SGLibType LibType)
01624 {
01625 TRACEUSER( "Matt", _T("AddGRMGroups Called in base class\n"));
01626 String_256 SectionName;
01627 WorkOutSectionName(&SectionName);
01628
01629
01630
01631 List *PathList = NULL;
01632 List *DescList = NULL;
01633 List *TypeList = NULL;
01634
01635 BOOL bRetVal = FALSE;
01636
01637 #ifdef SAVE_PREFS_TO_REGISTRY
01638
01639
01640
01641
01642
01643 String_256 KeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01644
01645 KeySectionName += SectionName;
01646
01647 BOOL SectionPresent = CheckForRegistryEntry(KeySectionName);
01648 if (SectionPresent)
01649 {
01650
01651
01652
01653 LoadRegistryEntries Loader;
01654 BOOL StartedOk = Loader.StartLoading(&KeySectionName);
01655 ERROR3IF(!StartedOk,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01656
01657 PathList = new List;
01658
01659
01660 BOOL AddedItems = FALSE;
01661 INT32 NumberSectionItems = 0;
01662 if (PathList && StartedOk)
01663 {
01664 String_256 Entry;
01665 while (Loader.LoadNextEntry(&Entry))
01666 {
01667 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&Entry);
01668 PathList->AddTail((ListItem *)LibSettingsItem);
01669 AddedItems = TRUE;
01670 }
01671
01672 NumberSectionItems = Loader.GetNumberOfItemsLoaded();
01673 Loader.StopLoading();
01674 }
01675
01676
01677 String_256 DescriptionSectionName;
01678 WorkOutDescriptionSectionName(&DescriptionSectionName);
01679
01680 String_256 DescriptionKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01681
01682 DescriptionKeySectionName += DescriptionSectionName;
01683 BOOL DescriptionsPresent = FALSE;
01684 String_256 DescEntry;
01685
01686
01687 LoadRegistryEntries DescLoader;
01688 DescriptionsPresent = DescLoader.StartLoading(&DescriptionKeySectionName);
01689 ERROR3IF(!DescriptionsPresent,"LibraryGallery::UpdateGRMFile couldn't start saving the settings");
01690
01691
01692 DescList = new List;
01693 INT32 NumberDescriptionItems = 0;
01694 if (DescList && DescriptionsPresent)
01695 {
01696 while (DescLoader.LoadNextEntry(&DescEntry))
01697 {
01698 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&DescEntry);
01699 DescList->AddTail((ListItem *)LibSettingsItem);
01700 AddedItems = TRUE;
01701 }
01702
01703 NumberDescriptionItems = DescLoader.GetNumberOfItemsLoaded();
01704 DescLoader.StopLoading();
01705 }
01706
01707
01708
01709 String_256 LibraryTypesSectionName;
01710 WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
01711
01712 String_256 LibraryTypesKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01713
01714 LibraryTypesKeySectionName += LibraryTypesSectionName;
01715 BOOL LibraryTypesPresent = FALSE;
01716 String_256 TypesEntry;
01717
01718
01719 LoadRegistryEntries TypesLoader;
01720 LibraryTypesPresent = TypesLoader.StartLoading(&LibraryTypesKeySectionName);
01721 ERROR3IF(!LibraryTypesPresent,"LibraryGallery::UpdateGRMFile couldn't start saving the LibraryTypes");
01722
01723
01724 TypeList = new List;
01725 INT32 NumberLibraryTypesItems = 0;
01726 if (TypeList && LibraryTypesPresent)
01727 {
01728 while (TypesLoader.LoadNextEntry(&TypesEntry))
01729 {
01730 LibSettingsListItem *LibSettingsItem = new LibSettingsListItem(&TypesEntry);
01731 TypeList->AddTail((ListItem *)LibSettingsItem);
01732 AddedItems = TRUE;
01733 }
01734
01735 NumberLibraryTypesItems = TypesLoader.GetNumberOfItemsLoaded();
01736 TypesLoader.StopLoading();
01737 }
01738
01739
01740
01741
01742 String_256 RootURLKeySectionName(PRODUCT_REGISTRYKEY_GALLERY TEXT("\\"));
01743
01744 RootURLKeySectionName += String_256(_R(IDS_ROOTURL));
01745 LoadRegistryEntries URLLoader;
01746 if (URLLoader.StartLoading(&RootURLKeySectionName))
01747 URLLoader.LoadNextEntry(&Library::URLBase);
01748 URLLoader.StopLoading();
01749
01750
01751
01752
01753 if (NumberDescriptionItems == NumberSectionItems &&
01754 NumberSectionItems != 0 && NumberDescriptionItems != 0 &&
01755 PathList != NULL && DescList != NULL)
01756 {
01757
01758 bRetVal = GoAndAddGRMGroups(TypeList , PathList, DescList, DescriptionsPresent, &SectionName, &DescriptionSectionName);
01759 }
01760 }
01761 else
01762 #endif
01763 {
01764
01765 String_256 Entry;
01766
01767
01768
01769
01770 FilePos SectionNamePos = 0;
01771 if(!LibSettings::GetEntry(&SectionName, 0, &Entry, &SectionNamePos))
01772 return FALSE;
01773
01774
01775 String_256 DescriptionSectionName(SectionName);
01776 WorkOutDescriptionSectionName(&DescriptionSectionName);
01777 BOOL DescriptionsPresent = FALSE;
01778 String_256 DescEntry;
01779 FilePos DescriptionPos = 0;
01780 if(LibSettings::GetEntry(&DescriptionSectionName, 0, &DescEntry, &DescriptionPos))
01781 DescriptionsPresent = TRUE;
01782
01783
01784
01785
01786
01787 if(DescriptionPos < SectionNamePos)
01788 DescriptionsPresent = FALSE;
01789
01790
01791 String_256 LibraryTypesSectionName(SectionName);
01792 WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
01793 BOOL LibraryTypesPresent = FALSE;
01794 String_256 TypeEntry;
01795 FilePos LibraryTypesPos = 0;
01796 if(LibSettings::GetEntry(&LibraryTypesSectionName, 0, &TypeEntry, &LibraryTypesPos))
01797 LibraryTypesPresent = TRUE;
01798
01799
01800 PathList = new List;
01801 if(PathList != NULL && !LibSettings::BuildList(&SectionName, PathList))
01802 {
01803 PathList->DeleteAll();
01804 delete PathList;
01805 PathList = NULL;
01806 }
01807
01808 DescList = NULL;
01809 if(DescriptionsPresent)
01810 {
01811 DescList = new List;
01812 if(DescList != NULL && !LibSettings::BuildList(&DescriptionSectionName, DescList))
01813 {
01814 DescList->DeleteAll();
01815 delete DescList;
01816 DescList = NULL;
01817 }
01818 }
01819
01820 TypeList = new List;
01821 if(LibraryTypesPresent)
01822 {
01823 TypeList = new List;
01824 if(TypeList != NULL && !LibSettings::BuildList(&LibraryTypesSectionName, TypeList))
01825 {
01826 TypeList->DeleteAll();
01827 delete TypeList;
01828 TypeList = NULL;
01829 }
01830 }
01831
01832
01833
01834
01835 String_256 strURLBaseSectionName(_R(IDS_ROOTURL));
01836 String_256 strRootURL;
01837 if (LibSettings::GetEntry(&strURLBaseSectionName, 1, &strRootURL, NULL))
01838 Library::URLBase = strRootURL;
01839
01840
01841 bRetVal = ActuallyAddGRMGroups(TypeList , PathList, DescList, DescriptionsPresent, &SectionName, &DescriptionSectionName);
01842
01843 }
01844
01845
01846 if(PathList != NULL)
01847 {
01848 PathList->DeleteAll();
01849 delete PathList;
01850 }
01851
01852 if(DescList != NULL)
01853 {
01854 DescList->DeleteAll();
01855 delete DescList;
01856 }
01857
01858 if(TypeList != NULL)
01859 {
01860 TypeList->DeleteAll();
01861 delete TypeList;
01862 }
01863
01864 return bRetVal;
01865 }
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893 BOOL LibraryGallery::GoAndAddGRMGroups( List *TypeList, List *PathList, List *DescList, BOOL DescPresent,
01894 String_256 *SectionName, String_256 *DescriptionSectionName)
01895 {
01896 ERROR2IF(PathList == NULL || DescList == NULL,FALSE,"GoAndAddGRMGroups bad lists!");
01897 ERROR2IF(SectionName == NULL || DescriptionSectionName == NULL,FALSE,"GoAndAddGRMGroups bad section names!");
01898
01899 ListItem *TypeItem = NULL;
01900 ListItem *PathItem = NULL;
01901 ListItem *DescItem = NULL;
01902 String_256 Entry;
01903 INT32 LineCount = 0;
01904 INT32 Line = 1;
01905 BOOL ValidLine = TRUE;
01906 BOOL GroupsAdded = FALSE;
01907
01908 LineCount = PathList->GetCount() + 1;
01909
01910
01911 String_256 strWebFoldersPath;
01912 GetAppCachePath(&strWebFoldersPath);
01913
01914 if (LineCount > 0)
01915 {
01916 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
01917 BeginSlowJob(LineCount, FALSE, &SlowJob);
01918
01919
01920 SetQuietStatus(FALSE);
01921
01922 Line = 1;
01923 ValidLine = TRUE;
01924
01925 BOOL EscapePressed = FALSE;
01926
01927 while (ValidLine && !EscapePressed)
01928 {
01929 EscapePressed = !ContinueSlowJob(Line);
01930
01931 if(PathItem == NULL)
01932 PathItem = PathList->GetHead();
01933 else
01934 PathItem = PathList->GetNext(PathItem);
01935 ValidLine = (PathItem != NULL && ((LibSettingsListItem *)PathItem)->Line != NULL);
01936 if (ValidLine)
01937 Entry = *((LibSettingsListItem *)PathItem)->Line;
01938 Line ++;
01939
01940 if (ValidLine)
01941 {
01942
01943 String_256 *pDescString = NULL;
01944 String_256 DescString;
01945 if (DescPresent)
01946 {
01947 if(DescItem == NULL)
01948 DescItem = DescList->GetHead();
01949 else
01950 DescItem = DescList->GetNext(DescItem);
01951
01952 if(DescItem != NULL && ((LibSettingsListItem *)DescItem)->Line != NULL)
01953 {
01954 DescString = *((LibSettingsListItem *)DescItem)->Line;
01955 pDescString = &DescString;
01956 }
01957 }
01958
01959 Line ++;
01960
01961
01962
01963 SGLibType m_SGLibType;
01964 String_256 TypeString;
01965 INT32 TypeInt;
01966 if (DescPresent)
01967 {
01968 if(TypeItem == NULL)
01969 TypeItem = TypeList->GetHead();
01970 else
01971 TypeItem = TypeList->GetNext(TypeItem);
01972
01973 if(TypeItem != NULL && ((LibSettingsListItem *)TypeItem)->Line != NULL)
01974 {
01975 INT32 pos = 0;
01976 TypeString = *((LibSettingsListItem *)TypeItem)->Line;
01977 TypeInt = TypeString.ConvertToInteger(pos);
01978 m_SGLibType = (SGLibType)TypeInt;
01979 }
01980 }
01981
01982
01983
01984 BOOL bIsWebFolder = !_tcsncicmp(Entry, strWebFoldersPath, _tcsclen(strWebFoldersPath));
01985
01986
01987
01988
01989
01990
01991
01992 BOOL bIsIndexPresent = (_access((TCHAR*) Entry, 0) != -1);
01993 if (!bIsWebFolder || (bIsWebFolder && bIsIndexPresent))
01994 {
01995
01996 LibraryFile *LibFile = new LibraryFile;
01997 if (LibFile != NULL)
01998 {
01999 PathName path(Entry);
02000 if(!LibFile->AddSpecificIndex(this, &path, m_SGLibType, pDescString, 0, bIsWebFolder))
02001 delete LibFile;
02002 else
02003 {
02004 OpenLibFiles.AddTail(LibFile);
02005 GroupsAdded = TRUE;
02006 }
02007 }
02008 }
02009 }
02010 }
02011 EndSlowJob();
02012 }
02013
02014 return GroupsAdded;
02015 }
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039 BOOL LibraryGallery::ActuallyAddGRMGroups( List *TypeList, List *PathList, List *DescList, BOOL DescPresent,
02040 String_256 *SectionName, String_256 *DescriptionSectionName)
02041 {
02042 ListItem *TypeItem = NULL;
02043 ListItem *PathItem = NULL;
02044 ListItem *DescItem = NULL;
02045 String_256 Entry;
02046 INT32 LineCount = 0;
02047 INT32 Line = 1;
02048 BOOL ValidLine = TRUE;
02049 BOOL GroupsAdded = FALSE;
02050
02051
02052 String_256 strWebFoldersPath;
02053 GetAppCachePath(&strWebFoldersPath);
02054
02055 if(PathList != NULL)
02056 LineCount = PathList->GetCount() + 1;
02057 else
02058 while(ValidLine)
02059 {
02060 ValidLine = LibSettings::GetEntry(SectionName, Line++, &Entry);
02061 LineCount ++;
02062 };
02063
02064 if(LineCount > 0)
02065 {
02066 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
02067 BeginSlowJob(LineCount, FALSE, &SlowJob);
02068
02069
02070 SetQuietStatus(FALSE);
02071
02072 Line = 1;
02073 ValidLine = TRUE;
02074
02075 BOOL EscapePressed = FALSE;
02076
02077 while(ValidLine && !EscapePressed)
02078 {
02079 EscapePressed = !ContinueSlowJob(Line);
02080
02081 if(PathList != NULL)
02082 {
02083 if(PathItem == NULL)
02084 PathItem = PathList->GetHead();
02085 else
02086 PathItem = PathList->GetNext(PathItem);
02087 ValidLine = (PathItem != NULL && ((LibSettingsListItem *)PathItem)->Line != NULL);
02088 if(ValidLine)
02089 Entry = *((LibSettingsListItem *)PathItem)->Line;
02090 Line ++;
02091 }
02092 else
02093 ValidLine = LibSettings::GetEntry(SectionName, Line++, &Entry);
02094
02095 if(ValidLine)
02096 {
02097
02098 String_256 *pDescString = NULL;
02099 String_256 DescString;
02100 if(DescPresent)
02101 {
02102 if(DescList != NULL)
02103 {
02104 if(DescItem == NULL)
02105 DescItem = DescList->GetHead();
02106 else
02107 DescItem = DescList->GetNext(DescItem);
02108
02109 if(DescItem != NULL && ((LibSettingsListItem *)DescItem)->Line != NULL)
02110 {
02111 DescString = *((LibSettingsListItem *)DescItem)->Line;
02112 pDescString = &DescString;
02113 }
02114 Line ++;
02115 }
02116 else
02117 {
02118 if(LibSettings::GetEntry(DescriptionSectionName, (Line-1), &DescString))
02119 pDescString = &DescString;
02120 }
02121 }
02122
02123
02124 SGLibType m_SGLibType;
02125 String_256 TypeString;
02126 INT32 TypeInt;
02127 if(DescPresent)
02128 {
02129 if(TypeList != NULL)
02130 {
02131 if(TypeItem == NULL)
02132 TypeItem = TypeList->GetHead();
02133 else
02134 TypeItem = TypeList->GetNext(DescItem);
02135
02136 if(TypeItem != NULL && ((LibSettingsListItem *)TypeItem)->Line != NULL)
02137 {
02138 INT32 pos = 0;
02139 TypeString = *((LibSettingsListItem *)TypeItem)->Line;
02140 TypeInt = TypeString.ConvertToInteger(pos);
02141 m_SGLibType = (SGLibType)TypeInt;
02142 }
02143 }
02144 else
02145 {
02146 String_256 LibraryTypesSectionName;
02147 WorkOutLibraryTypeSectionName(&LibraryTypesSectionName);
02148 if(LibSettings::GetEntry(&LibraryTypesSectionName, (Line-1), &TypeString))
02149 {
02150 INT32 pos = 0;
02151 TypeInt = TypeString.ConvertToInteger(pos);
02152 m_SGLibType = (SGLibType)TypeInt;
02153 }
02154 }
02155 }
02156
02157
02158
02159
02160
02161 BOOL bIsWebFolder = (camStrstr((TCHAR*) Entry, (TCHAR*) strWebFoldersPath) != NULL);
02162
02163
02164
02165
02166
02167
02168
02169 BOOL bIsIndexPresent = (_access((TCHAR*) Entry, 0) != -1);
02170 if (!bIsWebFolder || (bIsWebFolder && bIsIndexPresent))
02171 {
02172
02173 LibraryFile *LibFile = new LibraryFile;
02174 if (LibFile != NULL)
02175 {
02176
02177
02178 PathName path(Entry);
02179 if(!LibFile->AddSpecificIndex(this, &path, m_SGLibType, pDescString, 0, bIsWebFolder))
02180 delete LibFile;
02181 else
02182 {
02183 OpenLibFiles.AddTail(LibFile);
02184 GroupsAdded = TRUE;
02185 }
02186 }
02187 }
02188 }
02189 }
02190 EndSlowJob();
02191 }
02192
02193 return GroupsAdded;
02194 }
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210 INT32 LibraryGallery::LibraryGroupsInGallery(void)
02211 {
02212 return (OpenLibFiles.GetCount());
02213 }
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227 void LibraryGallery::GalleryAboutToClose(void)
02228 {
02229 TRACEUSER( "Richard", _T("Gallery about to close\n"));
02230
02231
02232 UpdateGRMFile();
02233
02234 String_64 ProgMsg(_R(IDS_GALLERY_FREEING_MEMORY_ON_CLOSE));
02235 BeginSlowJob(-1, TRUE, &ProgMsg);
02236
02237 if(FALSE)
02238 {
02239
02240 OpenLibFiles.DeleteAll();
02241 }
02242 else
02243 {
02244 if(!OpenLibFiles.IsEmpty())
02245 {
02246 INT32 LibFileCount = OpenLibFiles.GetCount();
02247
02248 if(LibFileCount > 0)
02249 {
02250
02251 for(INT32 LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
02252 {
02253 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
02254 INT32 LibCount = LibFile->Libraries.GetCount();
02255 if(LibCount > 0)
02256 {
02257
02258 for(INT32 LibLoop = 0; LibLoop < LibCount; LibLoop ++)
02259 {
02260 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop);
02261 if(Lib != NULL)
02262 Lib->FreeCachedIndexes();
02263 }
02264 }
02265 }
02266 }
02267 }
02268 }
02269
02270 EndSlowJob();
02271
02272 VirtualiseAllFoldedGroups();
02273 }
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289 void LibraryGallery::VirtualiseAllFoldedGroups(void)
02290 {
02291 const INT32 TimeLimit = 1 * 1000;
02292
02293 SGDisplayGroup *Group = (SGDisplayGroup *)GetDisplayTree()->GetChild();
02294 if(Group != NULL)
02295 {
02296 INT32 Groups = 0;
02297 while(Group != NULL)
02298 {
02299 Groups++;
02300 Group = (SGDisplayGroup *)Group->GetNext();
02301 }
02302
02303 String_64 ProgMsg(_R(IDS_GALLERY_FREEING_MEMORY_ON_CLOSE));
02304 BeginSlowJob(Groups, TRUE, &ProgMsg);
02305
02306 INT32 Count = 0;
02307 Group = (SGDisplayGroup *)GetDisplayTree()->GetChild();
02308
02309 MonotonicTime TimeCheck;
02310 BOOL DoneAGroup = FALSE;
02311
02312 while(Group != NULL)
02313 {
02314 if(ContinueSlowJob(Count++))
02315 {
02316 if(Group->Flags.Folded && !Group->IsVirtualised() && Group->CanVirtualise() && !Group->IsSelected()
02317 && !Group->Flags.Modified)
02318 {
02319 Group->Virtualise();
02320 DoneAGroup = TRUE;
02321 }
02322 Group = (SGDisplayGroup *)Group->GetNext();
02323 }
02324 else
02325 Group = NULL;
02326
02327
02328 if(DoneAGroup && TimeCheck.Elapsed(TimeLimit))
02329 Group = NULL;
02330 }
02331
02332 EndSlowJob();
02333 }
02334 }
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353 void LibraryGallery::GalleryAboutToReOpen(void)
02354 {
02355 TRACEUSER( "Richard", _T("Gallery about to open\n"));
02356
02357 if(!OpenLibFiles.IsEmpty())
02358 {
02359 INT32 LibFileCount = OpenLibFiles.GetCount();
02360
02361 if(LibFileCount > 0)
02362 {
02363
02364 INT32 GroupCount = 0;
02365 INT32 LibFileLoop = 0;
02366 for(LibFileLoop = 0; LibFileLoop < LibFileCount; LibFileLoop ++)
02367 {
02368 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop);
02369 if(LibFile != NULL)
02370 GroupCount += LibFile->Libraries.GetCount();
02371 }
02372
02373 if(GroupCount > 0)
02374 {
02375 String_64 SlowJob(_R(IDS_LIBRARY_CACHING_INDEXES));
02376 BeginSlowJob(GroupCount, FALSE, &SlowJob);
02377 }
02378
02379
02380 INT32 LibFilesDeleted = 0;
02381 INT32 OriginalLibFileCount = LibFileCount;
02382 INT32 ActualCount = 0;
02383
02384
02385 INT32 LastButtonPressed = 2;
02386
02387
02388 for(LibFileLoop = 0; LibFileLoop < OriginalLibFileCount; LibFileLoop ++)
02389 {
02390 LibraryFile *LibFile = (LibraryFile *)OpenLibFiles.FindItem(LibFileLoop - LibFilesDeleted);
02391 if(LibFile != NULL)
02392 {
02393 INT32 LibCount = LibFile->Libraries.GetCount();
02394 if(LibCount > 0)
02395 {
02396
02397 INT32 LibsDeleted = 0;
02398 INT32 OriginalLibCount = LibCount;
02399
02400
02401 for(INT32 LibLoop = 0; LibLoop < OriginalLibCount; LibLoop ++)
02402 {
02403
02404 Library *Lib = (Library *)LibFile->Libraries.FindItem(LibLoop - LibsDeleted);
02405 if(Lib != NULL)
02406 {
02407 if(LastButtonPressed != 3)
02408 LastButtonPressed = 2;
02409
02410 BOOL RepeatTheLoop = FALSE;
02411 BOOL Remove = FALSE;
02412 BOOL Recache = TRUE;
02413 do {
02414 RepeatTheLoop = FALSE;
02415
02416 Recache = Lib->ReCacheIndexes();
02417 if(!Recache)
02418 {
02419 if(LastButtonPressed != 3)
02420 {
02421 String_256 WarnMsg;
02422 String_256 Section;
02423 String_64 SmallSection;
02424 Lib->GetLibraryTitle(&Section);
02425 Section.Left(&SmallSection, 36);
02426
02427 WarnMsg.MakeMsg(_R(IDS_LIBRARY_CD_REMOVED), (TCHAR *)SmallSection);
02428
02429 Error::SetError(0, WarnMsg, 0);
02430 LastButtonPressed = InformWarning(0, _R(IDS_CONTINUE), _R(IDS_RETRY), _R(IDS_QUIET), NULL, 2, 1);
02431
02432
02433 if(LastButtonPressed == 2)
02434 RepeatTheLoop = TRUE;
02435 }
02436
02437 if(LastButtonPressed == 1 || LastButtonPressed == 3)
02438 Remove = TRUE;
02439 }
02440 } while(RepeatTheLoop);
02441
02442 if(Remove)
02443 {
02444
02445 Lib->ParentGroup->DestroySubtree(TRUE);
02446
02447
02448 delete(LibFile->Libraries.RemoveItem(Lib));
02449 LibsDeleted ++;
02450
02451
02452 LibCount = LibFile->Libraries.GetCount();
02453 if(LibCount == 0)
02454 {
02455 delete(OpenLibFiles.RemoveItem(LibFile));
02456 LibFilesDeleted ++;
02457 }
02458 }
02459 }
02460
02461 ContinueSlowJob(++ActualCount);
02462 }
02463 }
02464 }
02465 }
02466 EndSlowJob();
02467 }
02468 }
02469 }
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487 BOOL LibraryGallery::RemoveWebFolders(SGLibType type)
02488 {
02489 if (AskQuestion(_R(IDS_WARNREMOVE), _R(IDS_EMPTY), _R(IDS_CANCEL)) == _R(IDS_CANCEL))
02490 return FALSE;
02491
02492
02493 String_256 strLocation;
02494 GetAppDataPath(&strLocation);
02495 strLocation += GetStringField(type, _R(IDS_CACHEDIR));
02496
02497 if (_access((TCHAR*) strLocation, 0) != -1)
02498 {
02499 DownloadCache::Traverse(strLocation, TRUE);
02500 DownloadCache::Refresh();
02501 SelectionHasChanged();
02502 return TRUE;
02503 }
02504 else
02505 return FALSE;
02506 }
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525 void LibraryGallery::SuspendThumbnailDownloading()
02526
02527 {
02528 bThumbDownloading = FALSE;
02529 if (!m_lstPendingThumbs.empty())
02530 {
02531 OpThumbDownload::Suspend();
02532
02533 std::list<OpThumbDownload*>::iterator listIterator = m_lstPendingThumbs.begin();
02534 INT32 nListSize = m_lstPendingThumbs.size();
02535 for (INT32 i = 0; i < nListSize; i++)
02536 {
02537 OpThumbDownload* pDownloadOp = *listIterator++;
02538 ERROR3IF(!pDownloadOp || !pDownloadOp->IsKindOf(CC_RUNTIME_CLASS(OpThumbDownload)), "Ooops! Invalid pointer - we're about to crash");
02539 pDownloadOp->End();
02540 }
02541 OpThumbDownload::Resume();
02542 ERROR3IF(!m_lstPendingThumbs.empty(),"Failed to remove all pending downloads");
02543 }
02544 }
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561 void LibraryGallery::ResumeThumbnailDownloading()
02562 {
02563 OpThumbDownload::ClearErrors();
02564 bThumbDownloading = TRUE;
02565 }
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584 BOOL LibraryGallery::OnGetButtonClicked()
02585
02586 {
02587
02588
02589
02590
02591 if (!InternetManager::AttemptConnection())
02592 {
02593 InformError(_R(IDS_NOTCONNECTED), _R(IDS_OK));
02594 return FALSE;
02595 }
02596
02597 ResumeThumbnailDownloading();
02598 ForceRedrawOfList();
02599 if (OpAddWebFolders::Success[GetGalleryType()] && !m_bDiscardWebFolders)
02600 return TRUE;
02601 m_bDiscardWebFolders = FALSE;
02602 String_256 strIndexURL(GetStringField((UINT32) GetGalleryType(), _R(IDS_MAININDEXURL)));
02603
02604 String_256 strTempFile;
02605 GetTempInetDir(&strTempFile);
02606 strTempFile += GetStringField((UINT32) GetGalleryType(), _R(IDS_TMPFILES));
02607 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpAddWebFolders));
02608 if (pOpDesc != NULL)
02609 {
02610 AddWebFoldersParam* Param = new AddWebFoldersParam;
02611 ERROR2IF(!Param, FALSE, "Memory allocation error");
02612
02613 Param->localFile.SetPathName((TCHAR *) strTempFile);
02614 Param->strURL = strIndexURL;
02615 Param->pLibGal = this;
02616 Param->type = GetGalleryType();
02617
02618
02619 pOpDesc->Invoke((OpParam*) Param);
02620 }
02621 else
02622 {
02623 ERROR3("OpAddWebFolders not found");
02624 return FALSE;
02625 }
02626 return TRUE;
02627 }
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645 Library* LibraryGallery::FindLibrary(const String_256& rLibPath)
02646 {
02647 String_256 strLibPath(rLibPath);
02648 LibraryFile* pLibFile = (LibraryFile*) OpenLibFiles.GetHead();
02649 while (pLibFile)
02650 {
02651 Library* pLib = (Library*) pLibFile->Libraries.GetHead();
02652 while (pLib)
02653 {
02654 if (strLibPath.CompareTo(pLib->ReturnIndexLocation()->GetPath(), FALSE))
02655 pLib = (Library*) pLibFile->Libraries.GetNext(pLib);
02656 else
02657 return pLib;
02658 }
02659 pLibFile = (LibraryFile*) OpenLibFiles.GetNext(pLibFile);
02660 }
02661 return NULL;
02662 }