The MimeTypeListView now listens to changes to the MIME type database as well.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16363 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-02-12 17:11:58 +00:00
parent 9432e2e65a
commit 6ebc02eae4
3 changed files with 125 additions and 12 deletions

View File

@ -1025,11 +1025,17 @@ FileTypesWindow::MessageReceived(BMessage* message)
case B_META_MIME_CHANGED:
{
const char* type;
if (message->FindString("be:type", &type) != B_OK)
int32 which;
if (message->FindString("be:type", &type) != B_OK
|| message->FindInt32("be:which", &which) != B_OK)
break;
if (!strcasecmp(fCurrentType.Type(), type))
_SetType(&fCurrentType, true);
if (fCurrentType.Type() != NULL && !strcasecmp(fCurrentType.Type(), type)) {
if (which != B_MIME_TYPE_DELETED)
_SetType(&fCurrentType, true);
else
_SetType(NULL);
}
break;
}

View File

@ -29,7 +29,7 @@ mimetype_is_application_signature(BMimeType& type)
MimeTypeItem::MimeTypeItem(BMimeType& type, bool flat)
: BStringItem(type.Type(), !flat && type.IsSupertypeOnly() ? 1 : 0, false),
: BStringItem(type.Type(), !flat && !type.IsSupertypeOnly() ? 1 : 0, false),
fType(type.Type())
{
_SetTo(type);
@ -93,6 +93,9 @@ MimeTypeItem::_SetTo(BMimeType& type)
void
MimeTypeItem::Update()
{
if (IsSupertypeOnly())
return;
BMimeType type(fType.String());
char description[B_MIME_TYPE_LENGTH];
@ -222,7 +225,7 @@ MimeTypeListView::_CollectTypes()
void
MimeTypeListView::_MakeTypesUnique(MimeTypeItem* underItem)
{
SortItemsUnder(underItem, false, &MimeTypeItem::Compare);
SortItemsUnder(underItem, underItem != NULL, &MimeTypeItem::Compare);
bool lastItemSame = false;
MimeTypeItem* last = NULL;
@ -273,6 +276,109 @@ MimeTypeListView::_MakeTypesUnique(MimeTypeItem* underItem)
}
void
MimeTypeListView::AttachedToWindow()
{
BOutlineListView::AttachedToWindow();
BMimeType::StartWatching(this);
}
void
MimeTypeListView::DetachedFromWindow()
{
BOutlineListView::DetachedFromWindow();
BMimeType::StopWatching(this);
}
void
MimeTypeListView::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_META_MIME_CHANGED:
{
const char* type;
int32 which;
if (message->FindString("be:type", &type) != B_OK
|| message->FindInt32("be:which", &which) != B_OK)
break;
switch (which) {
case B_SHORT_DESCRIPTION_CHANGED:
{
// update label
MimeTypeItem* item = FindItem(type);
if (item != NULL)
UpdateItem(item);
break;
}
case B_MIME_TYPE_CREATED:
{
// create new item
BMimeType created(type);
BMimeType superType;
MimeTypeItem* superItem = NULL;
if (created.GetSupertype(&superType) == B_OK)
superItem = FindItem(superType.Type());
MimeTypeItem* item = new MimeTypeItem(created);
if (superItem != NULL) {
AddUnder(item, superItem);
InvalidateItem(IndexOf(superItem));
// the super item is not picked up from the class (ie. bug)
} else
AddItem(item);
UpdateItem(item);
break;
}
case B_MIME_TYPE_DELETED:
{
// delete item
MimeTypeItem* item = FindItem(type);
if (item != NULL) {
RemoveItem(item);
delete item;
}
break;
}
default:
break;
}
break;
}
default:
BOutlineListView::MessageReceived(message);
}
}
MimeTypeItem*
MimeTypeListView::FindItem(const char* type)
{
if (type == NULL)
return NULL;
for (int32 i = FullListCountItems(); i-- > 0;) {
MimeTypeItem* item = dynamic_cast<MimeTypeItem*>(FullListItemAt(i));
if (item == NULL)
continue;
if (!strcasecmp(item->Type(), type))
return item;
}
return NULL;
}
void
MimeTypeListView::UpdateItem(MimeTypeItem* item)
{
@ -294,9 +400,3 @@ MimeTypeListView::UpdateItem(MimeTypeItem* item)
InvalidateItem(IndexOf(item));
}
void
MimeTypeListView::RemoveItem(MimeTypeItem* item)
{
}

View File

@ -49,8 +49,15 @@ class MimeTypeListView : public BOutlineListView {
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
virtual ~MimeTypeListView();
MimeTypeItem* FindItem(const char* type);
void UpdateItem(MimeTypeItem* item);
void RemoveItem(MimeTypeItem* item);
protected:
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage* message);
private:
void _CollectTypes();