-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathflickr.lib.parallel.groups.load.pas
240 lines (217 loc) · 8.48 KB
/
flickr.lib.parallel.groups.load.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
// Copyright (c) 2015, Jordi Corbilla
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// - Neither the name of this library nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
unit flickr.lib.parallel.groups.load;
interface
uses
Classes, SysUtils, System.SyncObjs, Vcl.ComCtrls, vcl.taskbar, VCLtee.series, System.Win.taskbarcore, graphics, generics.collections,
flickr.base, flickr.lib.options.agent, flickr.xml.helper, System.AnsiStrings, flickr.filtered.list;
type
TParallelGroupLoad = class(TThread)
private
FRestURL : String;
FProgressbar : TProgressBar;
FTaskBar : TTaskbar;
FTotal : integer;
FlvGroups : TListView;
FPages: string;
FInitialize: boolean;
FOptionsAgent : IOptionsAgent;
FFilteredGroupList : TList<IBase>;
procedure DoInitialize();
procedure DoUpdate();
procedure AddAdditionalGroupDetails(base: IBase);
protected
procedure Execute; override;
public
constructor Create;
destructor Destroy(); override;
property restUrl : string read FRestUrl write FRestUrl;
property progressBar : TProgressBar read FProgressBar write FProgressBar;
property taskBar : TTaskBar read FTaskBar write FTaskBar;
property lvGroups: TListView read FlvGroups write FlvGroups;
property pages : string read FPages write FPages;
property Initialize : boolean read FInitialize write FInitialize;
property OptionsAgent : IOptionsAgent read FOptionsAgent write FOptionsAgent;
property FilteredGroupList: TList<IBase> read FFilteredGroupList write FFilteredGroupList;
end;
implementation
uses
Windows, flickr.http.lib, xmlintf, flickr.rest, flickr.list.comparer;
{ TParallelGroupLoad }
constructor TParallelGroupLoad.Create;
begin
inherited Create(True);
FFilteredGroupList := TList<IBase>.create;
FreeOnTerminate := False;
end;
destructor TParallelGroupLoad.Destroy;
begin
FFilteredGroupList.free;
inherited;
end;
procedure TParallelGroupLoad.DoInitialize;
begin
FlvGroups.Clear;
FProgressbar.Max := FTotal;
FTaskbar.ProgressState := TTaskBarProgressState.Normal;
FTaskbar.ProgressMaxValue := FTotal;
Fprogressbar.position := 0;
end;
procedure TParallelGroupLoad.DoUpdate;
begin
Fprogressbar.position := Fprogressbar.position + 1;
FTaskbar.ProgressValue := Fprogressbar.position;
end;
procedure TParallelGroupLoad.Execute;
begin
THttpRest.Post(FRestURL, procedure (iXMLRootNode : IXMLNode)
var
iXMLRootNode4: IXMLNode;
totalitems : string;
title, id, ismember: string;
photos : string;
members : string;
base : IBase;
begin
if FInitialize then
begin
FPages := iXMLRootNode.attributes['pages'];
totalitems := iXMLRootNode.attributes['total'];
end;
iXMLRootNode4 := iXMLRootNode.ChildNodes.first; // <group>
if FInitialize then
begin
FTotal := totalitems.ToInteger();
Synchronize(DoInitialize);
end;
while iXMLRootNode4 <> nil do
begin
if iXMLRootNode4.NodeName = 'group' then
begin
id := iXMLRootNode4.attributes['id'];
ismember := iXMLRootNode4.attributes['member'];
title := iXMLRootNode4.attributes['name'];
photos := iXMLRootNode4.attributes['photos'];
members := iXMLRootNode4.attributes['member_count'];
if ismember = '1' then
begin
base := TBase.New(id, title, StrToInt(photos), StrToInt(members));
AddAdditionalGroupDetails(base);
FFilteredGroupList.Add(base);
end;
end;
Synchronize(DoUpdate);
iXMLRootNode4 := iXMLRootNode4.NextSibling;
end;
end);
end;
procedure TParallelGroupLoad.AddAdditionalGroupDetails(base : IBase);
var
iXMLRootNode4: IXMLNode;
description : string;
IsModerated : boolean;
ThrottleCount : integer;
ThrottleMode : string;
ThrottleRemaining : integer;
photos_ok : boolean;
videos_ok : boolean;
images_ok : boolean;
screens_ok : boolean;
art_ok : boolean;
safe_ok : boolean;
moderate_ok : boolean;
restricted_ok : boolean;
has_geo : boolean;
begin
THttpRest.Post(TFlickrRest.New(FoptionsAgent).getGroupInfo(base.Id), procedure (iXMLRootNode : IXMLNode)
begin
description := '';
ThrottleCount := 0;
ThrottleMode := '';
ThrottleRemaining := 0;
photos_ok := false;
videos_ok := false;
images_ok := false;
screens_ok := false;
art_ok := false;
safe_ok := false;
moderate_ok := false;
restricted_ok := false;
has_geo := false;
try
IsModerated := TXMLHelper.new(iXMLRootNode.attributes['ispoolmoderated']).getBool;
iXMLRootNode4 := iXMLRootNode.ChildNodes.first; // <group>
while iXMLRootNode4 <> nil do
begin
if iXMLRootNode4.NodeName = 'description' then
begin
try
description := TXMLHelper.new(iXMLRootNode4.NodeValue).getString;
description := string(LeftStr(AnsiString(description), 200));
except
description := 'ERROR INVALID DESCRIPTION';
end;
end;
if iXMLRootNode4.NodeName = 'throttle' then
begin
ThrottleCount := TXMLHelper.new(iXMLRootNode4.attributes['count']).getInt;
ThrottleMode := TXMLHelper.new(iXMLRootNode4.attributes['mode']).getString;
ThrottleRemaining := TXMLHelper.new(iXMLRootNode4.attributes['remaining']).getInt;
end;
if iXMLRootNode4.NodeName = 'restrictions' then
begin
photos_ok := TXMLHelper.new(iXMLRootNode4.attributes['photos_ok']).getBool;
videos_ok := TXMLHelper.new(iXMLRootNode4.attributes['videos_ok']).getBool;
images_ok := TXMLHelper.new(iXMLRootNode4.attributes['images_ok']).getBool;
screens_ok := TXMLHelper.new(iXMLRootNode4.attributes['screens_ok']).getBool;
art_ok := TXMLHelper.new(iXMLRootNode4.attributes['art_ok']).getBool;
safe_ok := TXMLHelper.new(iXMLRootNode4.attributes['safe_ok']).getBool;
moderate_ok := TXMLHelper.new(iXMLRootNode4.attributes['moderate_ok']).getBool;
restricted_ok := TXMLHelper.new(iXMLRootNode4.attributes['restricted_ok']).getBool;
has_geo := TXMLHelper.new(iXMLRootNode4.attributes['has_geo']).getBool;
end;
iXMLRootNode4 := iXMLRootNode4.NextSibling;
end;
except
description := 'ERROR INVALID CHARACTERS';
end;
base.Description := description;
base.ThrottleCount := ThrottleCount;
base.ThrottleMode := ThrottleMode;
base.ThrottleRemaining := ThrottleRemaining;
base.photos_ok := photos_ok;
base.videos_ok := videos_ok;
base.images_ok := images_ok;
base.screens_ok := screens_ok;
base.art_ok := art_ok;
base.safe_ok := safe_ok;
base.moderate_ok := moderate_ok;
base.restricted_ok := restricted_ok;
base.has_geo := has_geo;
end);
end;
end.