/
PackageInfo.cpp
486 lines (377 loc) · 7.77 KB
/
PackageInfo.cpp
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
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "PackageInfo.h"
#include <stdio.h>
#include <Application.h>
#include <Bitmap.h>
#include <IconUtils.h>
#include <MimeType.h>
#include <Resources.h>
#include "support.h"
// #pragma mark - SharedBitmap
SharedBitmap::SharedBitmap(BBitmap* bitmap)
:
fResourceID(-1),
fMimeType()
{
fBitmap[0] = bitmap;
fBitmap[1] = NULL;
fBitmap[2] = NULL;
}
SharedBitmap::SharedBitmap(int32 resourceID)
:
fResourceID(resourceID),
fMimeType()
{
fBitmap[0] = NULL;
fBitmap[1] = NULL;
fBitmap[2] = NULL;
}
SharedBitmap::SharedBitmap(const char* mimeType)
:
fResourceID(-1),
fMimeType(mimeType)
{
fBitmap[0] = NULL;
fBitmap[1] = NULL;
fBitmap[2] = NULL;
}
SharedBitmap::~SharedBitmap()
{
delete fBitmap[0];
delete fBitmap[1];
delete fBitmap[2];
}
const BBitmap*
SharedBitmap::Bitmap(Size which)
{
if (fResourceID == -1 && fMimeType.Length() == 0)
return fBitmap[0];
int32 index = 0;
int32 size = 16;
switch (which) {
default:
case SIZE_16:
break;
case SIZE_32:
index = 1;
size = 32;
break;
case SIZE_64:
index = 2;
size = 64;
break;
}
if (fBitmap[index] == NULL) {
if (fResourceID >= 0)
fBitmap[index] = _CreateBitmapFromResource(size);
else if (fMimeType.Length() > 0)
fBitmap[index] = _CreateBitmapFromMimeType(size);
}
return fBitmap[index];
}
BBitmap*
SharedBitmap::_CreateBitmapFromResource(int32 size) const
{
BResources resources;
status_t status = get_app_resources(resources);
if (status != B_OK)
return NULL;
size_t dataSize;
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID,
&dataSize);
if (data == NULL)
return NULL;
BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, B_RGBA32);
status = bitmap->InitCheck();
if (status == B_OK) {
status = BIconUtils::GetVectorIcon(
reinterpret_cast<const uint8*>(data), dataSize, bitmap);
};
if (status != B_OK) {
delete bitmap;
bitmap = NULL;
}
return bitmap;
}
BBitmap*
SharedBitmap::_CreateBitmapFromMimeType(int32 size) const
{
BMimeType mimeType(fMimeType.String());
status_t status = mimeType.InitCheck();
if (status != B_OK)
return NULL;
BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, B_RGBA32);
status = bitmap->InitCheck();
if (status == B_OK)
status = mimeType.GetIcon(bitmap, B_MINI_ICON);
if (status != B_OK) {
delete bitmap;
bitmap = NULL;
}
return bitmap;
}
// #pragma mark - UserInfo
UserInfo::UserInfo()
:
fAvatar(),
fNickName()
{
}
UserInfo::UserInfo(const BString& nickName)
:
fAvatar(),
fNickName(nickName)
{
}
UserInfo::UserInfo(const BitmapRef& avatar, const BString& nickName)
:
fAvatar(avatar),
fNickName(nickName)
{
}
UserInfo::UserInfo(const UserInfo& other)
:
fAvatar(other.fAvatar),
fNickName(other.fNickName)
{
}
UserInfo&
UserInfo::operator=(const UserInfo& other)
{
fAvatar = other.fAvatar;
fNickName = other.fNickName;
return *this;
}
bool
UserInfo::operator==(const UserInfo& other) const
{
return fAvatar == other.fAvatar
&& fNickName == other.fNickName;
}
bool
UserInfo::operator!=(const UserInfo& other) const
{
return !(*this == other);
}
// #pragma mark - UserRating
UserRating::UserRating()
:
fUserInfo(),
fRating(0.0f),
fComment(),
fLanguage(),
fPackageVersion()
{
}
UserRating::UserRating(const UserInfo& userInfo, float rating,
const BString& comment, const BString& language,
const BString& packageVersion)
:
fUserInfo(userInfo),
fRating(rating),
fComment(comment),
fLanguage(language),
fPackageVersion(packageVersion)
{
}
UserRating::UserRating(const UserRating& other)
:
fUserInfo(other.fUserInfo),
fRating(other.fRating),
fComment(other.fComment),
fLanguage(other.fLanguage),
fPackageVersion(other.fPackageVersion)
{
}
UserRating&
UserRating::operator=(const UserRating& other)
{
fUserInfo = other.fUserInfo;
fRating = other.fRating;
fComment = other.fComment;
fLanguage = other.fLanguage;
fPackageVersion = other.fPackageVersion;
return *this;
}
bool
UserRating::operator==(const UserRating& other) const
{
return fUserInfo == other.fUserInfo
&& fRating == other.fRating
&& fComment == other.fComment
&& fLanguage == other.fLanguage
&& fPackageVersion == other.fPackageVersion;
}
bool
UserRating::operator!=(const UserRating& other) const
{
return !(*this == other);
}
// #pragma mark - PublisherInfo
PublisherInfo::PublisherInfo()
:
fLogo(),
fName(),
fEmail(),
fWebsite()
{
}
PublisherInfo::PublisherInfo(const BitmapRef& logo, const BString& name,
const BString& email, const BString& website)
:
fLogo(logo),
fName(name),
fEmail(email),
fWebsite(website)
{
}
PublisherInfo::PublisherInfo(const PublisherInfo& other)
:
fLogo(other.fLogo),
fName(other.fName),
fEmail(other.fEmail),
fWebsite(other.fWebsite)
{
}
PublisherInfo&
PublisherInfo::operator=(const PublisherInfo& other)
{
fLogo = other.fLogo;
fName = other.fName;
fEmail = other.fEmail;
fWebsite = other.fWebsite;
return *this;
}
bool
PublisherInfo::operator==(const PublisherInfo& other) const
{
return fLogo == other.fLogo
&& fName == other.fName
&& fEmail == other.fEmail
&& fWebsite == other.fWebsite;
}
bool
PublisherInfo::operator!=(const PublisherInfo& other) const
{
return !(*this == other);
}
// #pragma mark - PackageInfo
PackageInfo::PackageInfo()
:
fIcon(),
fTitle(),
fVersion(),
fPublisher(),
fShortDescription(),
fFullDescription(),
fChangelog(),
fUserRatings()
{
}
PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title,
const BString& version, const PublisherInfo& publisher,
const BString& shortDescription, const BString& fullDescription,
const BString& changelog)
:
fIcon(icon),
fTitle(title),
fVersion(version),
fPublisher(publisher),
fShortDescription(shortDescription),
fFullDescription(fullDescription),
fChangelog(changelog),
fUserRatings()
{
}
PackageInfo::PackageInfo(const PackageInfo& other)
:
fIcon(other.fIcon),
fTitle(other.fTitle),
fVersion(other.fVersion),
fPublisher(other.fPublisher),
fShortDescription(other.fShortDescription),
fFullDescription(other.fFullDescription),
fChangelog(other.fChangelog),
fUserRatings(other.fUserRatings)
{
}
PackageInfo&
PackageInfo::operator=(const PackageInfo& other)
{
fIcon = other.fIcon;
fTitle = other.fTitle;
fVersion = other.fVersion;
fPublisher = other.fPublisher;
fShortDescription = other.fShortDescription;
fFullDescription = other.fFullDescription;
fChangelog = other.fChangelog;
fUserRatings = other.fUserRatings;
return *this;
}
bool
PackageInfo::operator==(const PackageInfo& other) const
{
return fIcon == other.fIcon
&& fTitle == other.fTitle
&& fVersion == other.fVersion
&& fPublisher == other.fPublisher
&& fShortDescription == other.fShortDescription
&& fFullDescription == other.fFullDescription
&& fChangelog == other.fChangelog
&& fUserRatings == other.fUserRatings;
}
bool
PackageInfo::operator!=(const PackageInfo& other) const
{
return !(*this == other);
}
bool
PackageInfo::AddUserRating(const UserRating& rating)
{
return fUserRatings.Add(rating);
}
// #pragma mark -
DepotInfo::DepotInfo()
:
fTitle(),
fPackages()
{
}
DepotInfo::DepotInfo(const BString& title)
:
fTitle(title),
fPackages()
{
}
DepotInfo::DepotInfo(const DepotInfo& other)
:
fTitle(other.fTitle),
fPackages(other.fPackages)
{
}
DepotInfo&
DepotInfo::operator=(const DepotInfo& other)
{
fTitle = other.fTitle;
fPackages = other.fPackages;
return *this;
}
bool
DepotInfo::operator==(const DepotInfo& other) const
{
return fTitle == other.fTitle
&& fPackages == other.fPackages;
}
bool
DepotInfo::operator!=(const DepotInfo& other) const
{
return !(*this == other);
}
bool
DepotInfo::AddPackage(const PackageInfo& package)
{
return fPackages.Add(package);
}