More or less applied patch by anxiety that implements showing a file
icon in the MediaPlayer Info window. I changed it a bit, so that the icon retrieval only happens at the file change notification (quite important, since the info window receives playback position notifications). I also changed it to take the icon from the file first, if there is one. Thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28520 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -79,6 +79,8 @@ public:
|
|||||||
|
|
||||||
// Controller
|
// Controller
|
||||||
status_t SetTo(const entry_ref &ref);
|
status_t SetTo(const entry_ref &ref);
|
||||||
|
entry_ref Ref() const
|
||||||
|
{ return fRef; }
|
||||||
void PlayerActivated(bool active);
|
void PlayerActivated(bool active);
|
||||||
|
|
||||||
void GetSize(int *width, int *height);
|
void GetSize(int *width, int *height);
|
||||||
|
|||||||
@@ -23,8 +23,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Bitmap.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <MediaDefs.h>
|
#include <MediaDefs.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
@@ -48,18 +51,40 @@ const rgb_color kBlack = { 0, 0, 0, 255 };
|
|||||||
// should later draw an icon
|
// should later draw an icon
|
||||||
class InfoView : public BView {
|
class InfoView : public BView {
|
||||||
public:
|
public:
|
||||||
InfoView(BRect frame, const char *name, float divider)
|
InfoView(BRect frame, const char* name, float divider);
|
||||||
: BView(frame, name, B_FOLLOW_ALL,
|
virtual ~InfoView();
|
||||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
|
virtual void Draw(BRect updateRect);
|
||||||
, fDivider(divider)
|
|
||||||
{ }
|
status_t SetIcon(const entry_ref& ref);
|
||||||
virtual ~InfoView()
|
status_t SetIcon(const char* mimeType);
|
||||||
{ }
|
void SetGenericIcon();
|
||||||
void Draw(BRect updateRect);
|
|
||||||
float fDivider;
|
private:
|
||||||
|
float fDivider;
|
||||||
|
BBitmap* fIconBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
InfoView::InfoView(BRect frame, const char *name, float divider)
|
||||||
|
: BView(frame, name, B_FOLLOW_ALL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||||
|
fDivider(divider),
|
||||||
|
fIconBitmap(NULL)
|
||||||
|
{
|
||||||
|
BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
|
||||||
|
|
||||||
|
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||||
|
fIconBitmap = new BBitmap(rect, B_RGBA32);
|
||||||
|
#else
|
||||||
|
fIconBitmap = new BBitmap(rect, B_CMAP8);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InfoView::~InfoView()
|
||||||
|
{
|
||||||
|
delete fIconBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoView::Draw(BRect updateRect)
|
InfoView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
@@ -67,12 +92,66 @@ InfoView::Draw(BRect updateRect)
|
|||||||
BRect r(Bounds());
|
BRect r(Bounds());
|
||||||
r.right = r.left + fDivider;
|
r.right = r.left + fDivider;
|
||||||
FillRect(r);
|
FillRect(r);
|
||||||
|
|
||||||
|
if (fIconBitmap) {
|
||||||
|
float left = r.left + ( r.right - r.left ) / 2 - B_LARGE_ICON / 2;
|
||||||
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
DrawBitmap(fIconBitmap, BPoint(left, r.top + B_LARGE_ICON / 2));
|
||||||
|
}
|
||||||
|
|
||||||
SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR));
|
SetHighColor(ui_color(B_DOCUMENT_TEXT_COLOR));
|
||||||
r.left = r.right;
|
r.left = r.right;
|
||||||
FillRect(r);
|
FillRect(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
InfoView::SetIcon(const entry_ref& ref)
|
||||||
|
{
|
||||||
|
BNode node(&ref);
|
||||||
|
BNodeInfo info(&node);
|
||||||
|
return info.GetTrackerIcon(fIconBitmap, B_LARGE_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
InfoView::SetIcon(const char* mimeTypeString)
|
||||||
|
{
|
||||||
|
if (!mimeTypeString)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
// get type icon
|
||||||
|
BMimeType mimeType(mimeTypeString);
|
||||||
|
status_t status = mimeType.GetIcon(fIconBitmap, B_LARGE_ICON);
|
||||||
|
|
||||||
|
// get supertype icon
|
||||||
|
if (status != B_OK) {
|
||||||
|
BMimeType superType;
|
||||||
|
status = mimeType.GetSupertype(&superType);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = superType.GetIcon(fIconBitmap, B_LARGE_ICON);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoView::SetGenericIcon()
|
||||||
|
{
|
||||||
|
// get default icon
|
||||||
|
BMimeType genericType(B_FILE_MIME_TYPE);
|
||||||
|
if (genericType.GetIcon(fIconBitmap, B_LARGE_ICON) != B_OK) {
|
||||||
|
// clear bitmap
|
||||||
|
uint8 transparent = 0;
|
||||||
|
if (fIconBitmap->ColorSpace() == B_CMAP8)
|
||||||
|
transparent = B_TRANSPARENT_MAGIC_CMAP8;
|
||||||
|
|
||||||
|
memset(fIconBitmap->Bits(), transparent, fIconBitmap->BitsLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -101,14 +180,13 @@ InfoWin::InfoWin(BPoint leftTop, Controller* controller)
|
|||||||
rect.right - 10,
|
rect.right - 10,
|
||||||
20 + fh.ascent + 5),
|
20 + fh.ascent + 5),
|
||||||
"filename", "");
|
"filename", "");
|
||||||
|
AddChild(fFilenameView);
|
||||||
fFilenameView->SetFont(&bigFont);
|
fFilenameView->SetFont(&bigFont);
|
||||||
fFilenameView->SetViewColor(fInfoView->ViewColor());
|
fFilenameView->SetViewColor(fInfoView->ViewColor());
|
||||||
fFilenameView->SetLowColor(fInfoView->ViewColor());
|
fFilenameView->SetLowColor(fInfoView->ViewColor());
|
||||||
#ifdef B_BEOS_VERSION_DANO /* maybe we should support that as well ? */
|
#ifdef B_BEOS_VERSION_DANO /* maybe we should support that as well ? */
|
||||||
fFilenameView->SetTruncation(B_TRUNCATE_END);
|
fFilenameView->SetTruncation(B_TRUNCATE_END);
|
||||||
#endif
|
#endif
|
||||||
AddChild(fFilenameView);
|
|
||||||
|
|
||||||
|
|
||||||
rect.top = BASE_HEIGHT;
|
rect.top = BASE_HEIGHT;
|
||||||
|
|
||||||
@@ -268,7 +346,7 @@ printf("InfoWin::Update(0x%08lx)\n", which);
|
|||||||
|
|
||||||
// audio track format information
|
// audio track format information
|
||||||
if ((which & INFO_AUDIO) && fController->AudioTrackCount() > 0) {
|
if ((which & INFO_AUDIO) && fController->AudioTrackCount() > 0) {
|
||||||
fLabelsView->Insert("Audio\n\n\n\n");
|
fLabelsView->Insert("Audio\n\n\n");
|
||||||
BString s;
|
BString s;
|
||||||
media_format format;
|
media_format format;
|
||||||
media_raw_audio_format audioFormat;
|
media_raw_audio_format audioFormat;
|
||||||
@@ -361,14 +439,19 @@ printf("InfoWin::Update(0x%08lx)\n", which);
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (which & INFO_FILE) {
|
if (which & INFO_FILE) {
|
||||||
|
bool iconSet = false;
|
||||||
if (fController->HasFile()) {
|
if (fController->HasFile()) {
|
||||||
media_file_format ff;
|
entry_ref ref = fController->Ref();
|
||||||
|
iconSet = fInfoView->SetIcon(ref) == B_OK;
|
||||||
|
media_file_format fileFormat;
|
||||||
BString s;
|
BString s;
|
||||||
if (fController->GetFileFormatInfo(&ff) == B_OK) {
|
if (fController->GetFileFormatInfo(&fileFormat) == B_OK) {
|
||||||
fLabelsView->Insert("Container\n");
|
fLabelsView->Insert("Container\n");
|
||||||
s << ff.pretty_name;
|
s << fileFormat.pretty_name;
|
||||||
s << "\n";
|
s << "\n";
|
||||||
fContentsView->Insert(s.String());
|
fContentsView->Insert(s.String());
|
||||||
|
if (!iconSet)
|
||||||
|
iconSet = fInfoView->SetIcon(fileFormat.mime_type) == B_OK;
|
||||||
} else
|
} else
|
||||||
fContentsView->Insert("\n");
|
fContentsView->Insert("\n");
|
||||||
fLabelsView->Insert("Location\n");
|
fLabelsView->Insert("Location\n");
|
||||||
@@ -382,6 +465,8 @@ printf("InfoWin::Update(0x%08lx)\n", which);
|
|||||||
} else {
|
} else {
|
||||||
fFilenameView->SetText("<no media>");
|
fFilenameView->SetText("<no media>");
|
||||||
}
|
}
|
||||||
|
if (!iconSet)
|
||||||
|
fInfoView->SetGenericIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((which & INFO_COPYRIGHT) && fController->HasFile()) {
|
if ((which & INFO_COPYRIGHT) && fController->HasFile()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user