From c58a02bab692dc26e711668f20592740f851e5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 1 Aug 2013 22:56:51 +0200 Subject: [PATCH] HaikuDepot: Added icon loading from BMimeType to SharedBitmap * Also added publisher email and website fields to PackageInfo. --- src/apps/haiku-depot/MainWindow.cpp | 2 + src/apps/haiku-depot/PackageInfo.cpp | 71 ++++++++++++++++++++++++---- src/apps/haiku-depot/PackageInfo.h | 13 ++++- 3 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 35b88816d1..225a24baab 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -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.", + "superstippi@gmx.de", "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.", + "bpmagic@columbus.rr.com", "http://darkwyrm-haiku.blogspot.com", ""); paladin.AddUserRating( UserRating(UserInfo("stippi"), 3.5f, diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index 12bfa5a8d1..897120c082 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #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; } diff --git a/src/apps/haiku-depot/PackageInfo.h b/src/apps/haiku-depot/PackageInfo.h index 46fb90bbaf..44aa33a353 100644 --- a/src/apps/haiku-depot/PackageInfo.h +++ b/src/apps/haiku-depot/PackageInfo.h @@ -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; };