HaikuDepot: notify work status from main window
[haiku.git] / src / apps / patchbay / EndpointInfo.cpp
blob4dd14dad73661cd3ff80ec86594412a0f5e86767
1 /* EndpointInfo.cpp
2 * ----------------
3 * Implements the EndpointInfo object.
5 * Copyright 2013, Haiku, Inc. All rights reserved.
6 * Distributed under the terms of the MIT License.
8 * Revisions by Pete Goodeve
10 * Copyright 1999, Be Incorporated. All Rights Reserved.
11 * This file may be used under the terms of the Be Sample Code License.
13 #include "EndpointInfo.h"
15 #include <Bitmap.h>
16 #include <Debug.h>
17 #include <IconUtils.h>
18 #include <Message.h>
19 #include <MidiRoster.h>
20 #include <MidiEndpoint.h>
22 const char* LARGE_ICON_NAME = "be:large_icon";
23 const char* MINI_ICON_NAME = "be:mini_icon";
24 const char* VECTOR_ICON_NAME = "icon";
25 const uint32 LARGE_ICON_TYPE = 'ICON';
26 const uint32 MINI_ICON_TYPE = 'MICN';
27 const uint32 VECTOR_ICON_TYPE = 'VICN';
28 extern const uint8 LARGE_ICON_SIZE = 32;
29 extern const uint8 MINI_ICON_SIZE = 16;
30 extern const icon_size DISPLAY_ICON_SIZE = B_LARGE_ICON;
31 extern const color_space ICON_COLOR_SPACE = B_CMAP8;
33 static BBitmap* CreateIcon(const BMessage* msg, icon_size which);
36 EndpointInfo::EndpointInfo()
38 fId(-1),
39 fIcon(NULL)
43 EndpointInfo::EndpointInfo(int32 id)
45 fId(id),
46 fIcon(NULL)
48 BMidiRoster* roster = BMidiRoster::MidiRoster();
49 if (roster != NULL) {
50 BMidiEndpoint* endpoint = roster->FindEndpoint(id);
51 if (endpoint != NULL) {
52 printf("endpoint %" B_PRId32 " = %p\n", id, endpoint);
53 BMessage msg;
54 if (endpoint->GetProperties(&msg) == B_OK) {
55 fIcon = CreateIcon(&msg, DISPLAY_ICON_SIZE);
57 endpoint->Release();
63 EndpointInfo::EndpointInfo(const EndpointInfo& info)
65 fId(info.fId)
67 fIcon = (info.fIcon) ? new BBitmap(info.fIcon) : NULL;
71 EndpointInfo&
72 EndpointInfo::operator=(const EndpointInfo& info)
74 if (&info != this) {
75 fId = info.fId;
76 delete fIcon;
77 fIcon = (info.fIcon) ? new BBitmap(info.fIcon) : NULL;
79 return *this;
83 EndpointInfo::~EndpointInfo()
85 delete fIcon;
89 void
90 EndpointInfo::UpdateProperties(const BMessage* props)
92 delete fIcon;
93 fIcon = CreateIcon(props, DISPLAY_ICON_SIZE);
97 static BBitmap*
98 CreateIcon(const BMessage* msg, icon_size which)
101 const void* data;
102 ssize_t size;
103 BBitmap* bitmap = NULL;
105 // See if a Haiku Vector Icon available
106 if (msg->FindData(VECTOR_ICON_NAME, VECTOR_ICON_TYPE, &data,
107 &size) == B_OK) {
108 BRect r(0, 0, LARGE_ICON_SIZE - 1, LARGE_ICON_SIZE - 1);
109 bitmap = new BBitmap(r, B_RGBA32);
110 if (BIconUtils::GetVectorIcon((const uint8*)data, size,
111 bitmap) == B_OK) {
112 printf("Created vector icon bitmap\n");
113 return bitmap;
114 } else {
115 delete bitmap;
116 bitmap = NULL;
120 // If not, look for BeOS style icon
121 float bmapSize;
122 uint32 iconType;
123 const char* iconName;
125 if (which == B_LARGE_ICON) {
126 bmapSize = LARGE_ICON_SIZE - 1;
127 iconType = LARGE_ICON_TYPE;
128 iconName = LARGE_ICON_NAME;
129 } else if (which == B_MINI_ICON) {
130 bmapSize = MINI_ICON_SIZE - 1;
131 iconType = MINI_ICON_TYPE;
132 iconName = MINI_ICON_NAME;
133 } else
134 return NULL;
136 if (msg->FindData(iconName, iconType, &data, &size) == B_OK) {
137 bitmap = new BBitmap(BRect(0, 0, bmapSize, bmapSize),
138 ICON_COLOR_SPACE);
139 ASSERT((bitmap->BitsLength() == size));
140 memcpy(bitmap->Bits(), data, size);
142 return bitmap;