HaikuDepot: Added icon loading from BMimeType to SharedBitmap

* Also added publisher email and website fields to PackageInfo.
This commit is contained in:
Stephan Aßmus
2013-08-01 22:56:51 +02:00
parent a56422b448
commit c58a02bab6
3 changed files with 75 additions and 11 deletions
+2
View File
@@ -160,6 +160,7 @@ MainWindow::_InitDummyModel()
"WonderBrush is YellowBites' software for doing graphics design " "WonderBrush is YellowBites' software for doing graphics design "
"on Haiku. It combines many great under-the-hood features with " "on Haiku. It combines many great under-the-hood features with "
"powerful tools and an efficient and intuitive interface.", "powerful tools and an efficient and intuitive interface.",
"[email protected]", "http://www.yellowbites.com",
"2.1.2 - Initial Haiku release."); "2.1.2 - Initial Haiku release.");
wonderbrush.AddUserRating( wonderbrush.AddUserRating(
UserRating(UserInfo("humdinger"), 4.5f, UserRating(UserInfo("humdinger"), 4.5f,
@@ -180,6 +181,7 @@ MainWindow::_InitDummyModel()
"The interface is streamlined, it has some features sorely " "The interface is streamlined, it has some features sorely "
"missing from BeIDE, like running a project in the Terminal, " "missing from BeIDE, like running a project in the Terminal, "
"and has a bundled text editor based upon Pe.", "and has a bundled text editor based upon Pe.",
"[email protected]", "http://darkwyrm-haiku.blogspot.com",
""); "");
paladin.AddUserRating( paladin.AddUserRating(
UserRating(UserInfo("stippi"), 3.5f, UserRating(UserInfo("stippi"), 3.5f,
+61 -10
View File
@@ -10,6 +10,7 @@
#include <Application.h> #include <Application.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <IconUtils.h> #include <IconUtils.h>
#include <MimeType.h>
#include <Resources.h> #include <Resources.h>
#include "support.h" #include "support.h"
@@ -20,7 +21,8 @@
SharedBitmap::SharedBitmap(BBitmap* bitmap) SharedBitmap::SharedBitmap(BBitmap* bitmap)
: :
fResourceID(-1) fResourceID(-1),
fMimeType()
{ {
fBitmap[0] = bitmap; fBitmap[0] = bitmap;
fBitmap[1] = NULL; fBitmap[1] = NULL;
@@ -30,7 +32,8 @@ SharedBitmap::SharedBitmap(BBitmap* bitmap)
SharedBitmap::SharedBitmap(int32 resourceID) SharedBitmap::SharedBitmap(int32 resourceID)
: :
fResourceID(resourceID) fResourceID(resourceID),
fMimeType()
{ {
fBitmap[0] = NULL; fBitmap[0] = NULL;
fBitmap[1] = NULL; fBitmap[1] = NULL;
@@ -38,6 +41,25 @@ SharedBitmap::SharedBitmap(int32 resourceID)
} }
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* const BBitmap*
SharedBitmap::Bitmap(Size which) SharedBitmap::Bitmap(Size which)
{ {
@@ -62,15 +84,19 @@ SharedBitmap::Bitmap(Size which)
break; break;
} }
if (fBitmap[index] == NULL) if (fBitmap[index] == NULL) {
fBitmap[index] = _CreateBitmap(size); if (fResourceID >= 0)
fBitmap[index] = _CreateBitmapFromResource(size);
else if (fMimeType.Length() > 0)
fBitmap[index] = _CreateBitmapFromMimeType(size);
}
return fBitmap[index]; return fBitmap[index];
} }
BBitmap* BBitmap*
SharedBitmap::_CreateBitmap(int32 size) const SharedBitmap::_CreateBitmapFromResource(int32 size) const
{ {
BResources resources; BResources resources;
status_t status = get_app_resources(resources); status_t status = get_app_resources(resources);
@@ -99,11 +125,25 @@ SharedBitmap::_CreateBitmap(int32 size) const
} }
SharedBitmap::~SharedBitmap() BBitmap*
SharedBitmap::_CreateBitmapFromMimeType(int32 size) const
{ {
delete fBitmap[0]; BMimeType mimeType(fMimeType.String());
delete fBitmap[1]; status_t status = mimeType.InitCheck();
delete fBitmap[2]; 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_LARGE_ICON);
if (status != B_OK) {
delete bitmap;
bitmap = NULL;
}
return bitmap;
} }
@@ -245,6 +285,8 @@ PackageInfo::PackageInfo()
fVersion(), fVersion(),
fShortDescription(), fShortDescription(),
fFullDescription(), fFullDescription(),
fPublisherEmail(),
fPublisherWebsite(),
fChangelog(), fChangelog(),
fUserRatings() fUserRatings()
{ {
@@ -253,13 +295,16 @@ PackageInfo::PackageInfo()
PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title, PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title,
const BString& version, const BString& shortDescription, const BString& version, const BString& shortDescription,
const BString& fullDescription, const BString& changelog) const BString& fullDescription, const BString& publisherEmail,
const BString& publisherWebsite, const BString& changelog)
: :
fIcon(icon), fIcon(icon),
fTitle(title), fTitle(title),
fVersion(version), fVersion(version),
fShortDescription(shortDescription), fShortDescription(shortDescription),
fFullDescription(fullDescription), fFullDescription(fullDescription),
fPublisherEmail(publisherEmail),
fPublisherWebsite(publisherWebsite),
fChangelog(changelog), fChangelog(changelog),
fUserRatings() fUserRatings()
{ {
@@ -273,6 +318,8 @@ PackageInfo::PackageInfo(const PackageInfo& other)
fVersion(other.fVersion), fVersion(other.fVersion),
fShortDescription(other.fShortDescription), fShortDescription(other.fShortDescription),
fFullDescription(other.fFullDescription), fFullDescription(other.fFullDescription),
fPublisherEmail(other.fPublisherEmail),
fPublisherWebsite(other.fPublisherWebsite),
fChangelog(other.fChangelog), fChangelog(other.fChangelog),
fUserRatings(other.fUserRatings) fUserRatings(other.fUserRatings)
{ {
@@ -287,6 +334,8 @@ PackageInfo::operator=(const PackageInfo& other)
fVersion = other.fVersion; fVersion = other.fVersion;
fShortDescription = other.fShortDescription; fShortDescription = other.fShortDescription;
fFullDescription = other.fFullDescription; fFullDescription = other.fFullDescription;
fPublisherEmail = other.fPublisherEmail;
fPublisherWebsite = other.fPublisherWebsite;
fChangelog = other.fChangelog; fChangelog = other.fChangelog;
fUserRatings = other.fUserRatings; fUserRatings = other.fUserRatings;
return *this; return *this;
@@ -301,6 +350,8 @@ PackageInfo::operator==(const PackageInfo& other) const
&& fVersion == other.fVersion && fVersion == other.fVersion
&& fShortDescription == other.fShortDescription && fShortDescription == other.fShortDescription
&& fFullDescription == other.fFullDescription && fFullDescription == other.fFullDescription
&& fPublisherEmail == other.fPublisherEmail
&& fPublisherWebsite == other.fPublisherWebsite
&& fChangelog == other.fChangelog && fChangelog == other.fChangelog
&& fUserRatings == other.fUserRatings; && fUserRatings == other.fUserRatings;
} }
+12 -1
View File
@@ -25,15 +25,18 @@ public:
SharedBitmap(BBitmap* bitmap); SharedBitmap(BBitmap* bitmap);
SharedBitmap(int32 resourceID); SharedBitmap(int32 resourceID);
SharedBitmap(const char* mimeType);
~SharedBitmap(); ~SharedBitmap();
const BBitmap* Bitmap(Size which); const BBitmap* Bitmap(Size which);
private: private:
BBitmap* _CreateBitmap(int32 size) const; BBitmap* _CreateBitmapFromResource(int32 size) const;
BBitmap* _CreateBitmapFromMimeType(int32 size) const;
private: private:
int32 fResourceID; int32 fResourceID;
BString fMimeType;
BBitmap* fBitmap[3]; BBitmap* fBitmap[3];
}; };
@@ -109,6 +112,8 @@ public:
const BString& version, const BString& version,
const BString& shortDescription, const BString& shortDescription,
const BString& fullDescription, const BString& fullDescription,
const BString& publisherEmail,
const BString& publisherWebsite,
const BString& changelog); const BString& changelog);
PackageInfo(const PackageInfo& other); PackageInfo(const PackageInfo& other);
@@ -126,6 +131,10 @@ public:
{ return fShortDescription; } { return fShortDescription; }
const BString& FullDescription() const const BString& FullDescription() const
{ return fFullDescription; } { return fFullDescription; }
const BString& PublisherEmail() const
{ return fPublisherEmail; }
const BString& PublisherWebsite() const
{ return fPublisherWebsite; }
const BString& Changelog() const const BString& Changelog() const
{ return fChangelog; } { return fChangelog; }
@@ -137,6 +146,8 @@ private:
BString fVersion; BString fVersion;
BString fShortDescription; BString fShortDescription;
BString fFullDescription; BString fFullDescription;
BString fPublisherEmail;
BString fPublisherWebsite;
BString fChangelog; BString fChangelog;
UserRatingList fUserRatings; UserRatingList fUserRatings;
}; };