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 "
"on Haiku. It combines many great under-the-hood features with "
"powerful tools and an efficient and intuitive interface.",
"[email protected]", "http://www.yellowbites.com",
"2.1.2 - Initial Haiku release.");
wonderbrush.AddUserRating(
UserRating(UserInfo("humdinger"), 4.5f,
@@ -180,6 +181,7 @@ MainWindow::_InitDummyModel()
"The interface is streamlined, it has some features sorely "
"missing from BeIDE, like running a project in the Terminal, "
"and has a bundled text editor based upon Pe.",
"[email protected]", "http://darkwyrm-haiku.blogspot.com",
"");
paladin.AddUserRating(
UserRating(UserInfo("stippi"), 3.5f,
+61 -10
View File
@@ -10,6 +10,7 @@
#include <Application.h>
#include <Bitmap.h>
#include <IconUtils.h>
#include <MimeType.h>
#include <Resources.h>
#include "support.h"
@@ -20,7 +21,8 @@
SharedBitmap::SharedBitmap(BBitmap* bitmap)
:
fResourceID(-1)
fResourceID(-1),
fMimeType()
{
fBitmap[0] = bitmap;
fBitmap[1] = NULL;
@@ -30,7 +32,8 @@ SharedBitmap::SharedBitmap(BBitmap* bitmap)
SharedBitmap::SharedBitmap(int32 resourceID)
:
fResourceID(resourceID)
fResourceID(resourceID),
fMimeType()
{
fBitmap[0] = 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*
SharedBitmap::Bitmap(Size which)
{
@@ -62,15 +84,19 @@ SharedBitmap::Bitmap(Size which)
break;
}
if (fBitmap[index] == NULL)
fBitmap[index] = _CreateBitmap(size);
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::_CreateBitmap(int32 size) const
SharedBitmap::_CreateBitmapFromResource(int32 size) const
{
BResources 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];
delete fBitmap[1];
delete fBitmap[2];
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_LARGE_ICON);
if (status != B_OK) {
delete bitmap;
bitmap = NULL;
}
return bitmap;
}
@@ -245,6 +285,8 @@ PackageInfo::PackageInfo()
fVersion(),
fShortDescription(),
fFullDescription(),
fPublisherEmail(),
fPublisherWebsite(),
fChangelog(),
fUserRatings()
{
@@ -253,13 +295,16 @@ PackageInfo::PackageInfo()
PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title,
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),
fTitle(title),
fVersion(version),
fShortDescription(shortDescription),
fFullDescription(fullDescription),
fPublisherEmail(publisherEmail),
fPublisherWebsite(publisherWebsite),
fChangelog(changelog),
fUserRatings()
{
@@ -273,6 +318,8 @@ PackageInfo::PackageInfo(const PackageInfo& other)
fVersion(other.fVersion),
fShortDescription(other.fShortDescription),
fFullDescription(other.fFullDescription),
fPublisherEmail(other.fPublisherEmail),
fPublisherWebsite(other.fPublisherWebsite),
fChangelog(other.fChangelog),
fUserRatings(other.fUserRatings)
{
@@ -287,6 +334,8 @@ PackageInfo::operator=(const PackageInfo& other)
fVersion = other.fVersion;
fShortDescription = other.fShortDescription;
fFullDescription = other.fFullDescription;
fPublisherEmail = other.fPublisherEmail;
fPublisherWebsite = other.fPublisherWebsite;
fChangelog = other.fChangelog;
fUserRatings = other.fUserRatings;
return *this;
@@ -301,6 +350,8 @@ PackageInfo::operator==(const PackageInfo& other) const
&& fVersion == other.fVersion
&& fShortDescription == other.fShortDescription
&& fFullDescription == other.fFullDescription
&& fPublisherEmail == other.fPublisherEmail
&& fPublisherWebsite == other.fPublisherWebsite
&& fChangelog == other.fChangelog
&& fUserRatings == other.fUserRatings;
}
+12 -1
View File
@@ -25,15 +25,18 @@ public:
SharedBitmap(BBitmap* bitmap);
SharedBitmap(int32 resourceID);
SharedBitmap(const char* mimeType);
~SharedBitmap();
const BBitmap* Bitmap(Size which);
private:
BBitmap* _CreateBitmap(int32 size) const;
BBitmap* _CreateBitmapFromResource(int32 size) const;
BBitmap* _CreateBitmapFromMimeType(int32 size) const;
private:
int32 fResourceID;
BString fMimeType;
BBitmap* fBitmap[3];
};
@@ -109,6 +112,8 @@ public:
const BString& version,
const BString& shortDescription,
const BString& fullDescription,
const BString& publisherEmail,
const BString& publisherWebsite,
const BString& changelog);
PackageInfo(const PackageInfo& other);
@@ -126,6 +131,10 @@ public:
{ return fShortDescription; }
const BString& FullDescription() const
{ return fFullDescription; }
const BString& PublisherEmail() const
{ return fPublisherEmail; }
const BString& PublisherWebsite() const
{ return fPublisherWebsite; }
const BString& Changelog() const
{ return fChangelog; }
@@ -137,6 +146,8 @@ private:
BString fVersion;
BString fShortDescription;
BString fFullDescription;
BString fPublisherEmail;
BString fPublisherWebsite;
BString fChangelog;
UserRatingList fUserRatings;
};