Icons Screensaver: Get icons from MIME db again

The previous method only queried application icons, not document icons.

Unfortunately, the app icons in the MIME DB are broken/not present.
IconsSaver only displays document icons for the time being.

Because of better error checking the garbled icons are filtered out though
at least.

Next step is to fix the application icons in the MIME DB.

Some other changes:
* Don't draw if the BBitmap was not filled out correctly
* Add Vincent Duvert to authors list, he's already in copyright
* Convert fVectorIcons from a BList to a BObjectList
* Put vector_icon struct in it’s own header (needed for above)
* Remove type param from vector_icon struct
* Bump max icon count to 300, hopefully this should be enough, 128
  is too few for app and document icons in default install.
This commit is contained in:
John Scipione 2014-01-24 03:44:09 -05:00
parent 82bcd89b92
commit 1c56a03c51
6 changed files with 85 additions and 76 deletions

View File

@ -5,17 +5,20 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* Vincent Duvert, vincent.duvert@free.fr
* John Scipione, jscipione@gmail.com
*/
#include "IconDisplay.h"
#include <stdio.h>
#include <stdlib.h>
#include <Bitmap.h>
#include <IconUtils.h>
#include <View.h>
#include "VectorIcon.h"
#define RAND_BETWEEN(a, b) ((rand() % ((b) - (a) + 1) + (a)))
@ -48,7 +51,8 @@ IconDisplay::Run(vector_icon* icon, BRect frame)
fBitmap = new BBitmap(BRect(0, 0, frame.Width(), frame.Height()), 0,
B_RGBA32);
BIconUtils::GetVectorIcon(icon->data, icon->size, fBitmap);
if (BIconUtils::GetVectorIcon(icon->data, icon->size, fBitmap) != B_OK)
return;
fState = 0;
fTicks = 0;
@ -80,26 +84,28 @@ IconDisplay::DrawOn(BView* view, uint32 delta)
rgb_color backColor = view->HighColor();
switch (fState) {
case 0:
// Progressive showing
case 0:
// progressive showing
if (fTicks < fDelay)
backColor.alpha = (fTicks * 255) / fDelay;
else
fState++;
break;
case 1:
// Completed showing
case 1:
// completed showing
backColor.alpha = 255;
fTicks = 0;
fDelay = RAND_BETWEEN(STAY_TICKS_MIN, STAY_TICKS_MAX);
fState++;
break;
case 2:
// Waiting
case 2:
// waiting
if (fTicks < fDelay)
return;
fTicks = 0;
backColor.alpha = 255;
fDelay = RAND_BETWEEN(HIDE_TICKS_MIN, HIDE_TICKS_MAX);
@ -107,8 +113,8 @@ IconDisplay::DrawOn(BView* view, uint32 delta)
return;
break;
case 3:
// Progressive hiding
case 3:
// progressive hiding
if (fTicks < fDelay) {
backColor.alpha = 255 - (fTicks * 255) / fDelay;
} else {
@ -117,8 +123,8 @@ IconDisplay::DrawOn(BView* view, uint32 delta)
}
break;
default:
// Finished
default:
// finished
fIsRunning = false;
return;
break;

View File

@ -5,6 +5,7 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* Vincent Duvert, vincent.duvert@free.fr
* John Scipione, jscipione@gmail.com
*/
#ifndef ICON_DISPLAY_H
@ -12,18 +13,13 @@
#include <Rect.h>
#include <SupportDefs.h>
#include <View.h>
struct vector_icon {
uint8* data;
size_t size;
type_code type;
};
struct vector_icon;
class BBitmap;
class BView;
class IconDisplay {

View File

@ -5,29 +5,24 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* Vincent Duvert, vincent.duvert@free.fr
* John Scipione, jscipione@gmail.com
*/
#include "IconsSaver.h"
#include <stdio.h>
#include <stdlib.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <Entry.h>
#include <MimeType.h>
#include <Node.h>
#include <NodeInfo.h>
#include <StringView.h>
#include <Query.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <BuildScreenSaverDefaultSettingsView.h>
#include "IconDisplay.h"
#include "VectorIcon.h"
#undef B_TRANSLATION_CONTEXT
@ -43,13 +38,12 @@ static const int32 kMinIconWidthPercentage = 5;
static const int32 kMaxIconWidthPercentage = 20;
// same here
static const int32 kMinIconCount = 20;
static const int32 kMaxIconCount = 128;
static const int32 kMaxIconCount = 300;
const rgb_color kBackgroundColor = ui_color(B_DESKTOP_COLOR);
BScreenSaver* instantiate_screen_saver(BMessage* msg, image_id image)
{
return new IconsSaver(msg, image);
@ -172,7 +166,7 @@ IconsSaver::Draw(BView* view, int32 frame)
}
int32 index = RAND_BETWEEN(0, fVectorIcons.CountItems() - 1);
fIcons[i].Run((vector_icon*)fVectorIcons.ItemAt(index), iconFrame);
fIcons[i].Run(fVectorIcons.ItemAt(index), iconFrame);
return;
}
}
@ -193,49 +187,32 @@ IconsSaver::StartConfig(BView* view)
void
IconsSaver::_GetVectorIcons()
{
BVolumeRoster volumeRoster;
BVolume volume;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
if (!volume.KnowsAttr() || !volume.KnowsMime() || !volume.KnowsQuery())
// Load vector icons from the MIME type database
BMessage types;
if (BMimeType::GetInstalledTypes(&types) != B_OK)
return;
const char* type;
for (int32 i = 0; types.FindString("types", i, &type) == B_OK; i++) {
BMimeType mimeType(type);
if (mimeType.InitCheck() != B_OK)
continue;
BQuery query;
query.SetVolume(&volume);
query.SetPredicate("BEOS:APP_SIG=*");
query.Fetch();
vector_icon* icon = (vector_icon*)malloc(sizeof(vector_icon));
if (icon == NULL)
continue;
entry_ref ref;
while (query.GetNextRef(&ref) == B_OK) {
BFile file(&ref, B_READ_ONLY);
if (file.InitCheck() != B_OK)
continue;
if (mimeType.GetIcon(&icon->data, &icon->size) != B_OK) {
// didn't find an icon, delete the icon container
delete icon;
continue;
}
struct vector_icon* icon
= (struct vector_icon*)malloc(sizeof(struct vector_icon));
if (icon == NULL)
continue;
BNode node(&ref);
BNodeInfo nodeInfo(&node);
if (nodeInfo.InitCheck() != B_OK
|| nodeInfo.GetIcon(&icon->data, &icon->size, &icon->type)
!= B_OK) {
// didn't find an icon
continue;
}
if (icon->type != B_VECTOR_ICON_TYPE) {
// found an icon, but it's not a vector icon
delete icon;
continue;
}
// found a vector icon, add it to the list
fVectorIcons.AddItem(icon);
if (fVectorIcons.CountItems() >= kMaxIconCount) {
// this is enough to choose from, stop eating memory...
return;
}
// found a vector icon, add it to the list
fVectorIcons.AddItem(icon);
if (fVectorIcons.CountItems() >= kMaxIconCount) {
// this is enough to choose from, stop eating memory...
return;
}
}
}

View File

@ -5,16 +5,20 @@
* Distributed under the terms of the MIT License.
*
* Authors:
* Vincent Duvert, vincent.duvert@free.fr
* John Scipione, jscipione@gmail.com
*/
#ifndef ICONS_SAVER_H
#define ICONS_SAVER_H
#include <List.h>
#include <ObjectList.h>
#include <ScreenSaver.h>
struct vector_icon;
class IconDisplay;
@ -33,7 +37,7 @@ public:
private:
void _GetVectorIcons();
BList fVectorIcons;
BObjectList<vector_icon> fVectorIcons;
IconDisplay* fIcons;
BBitmap* fBackBitmap;

View File

@ -0,0 +1,21 @@
/*
* Copyright 2009 Vincent Duvert, vincent.duvert@free.fr
* Copyright 2014 Haiku, Inc. All rights reserved.
*
* Distributed under the terms of the MIT License.
*
* Authors:
* Vincent Duvert, vincent.duvert@free.fr
* John Scipione, jscipione@gmail.com
*/
#ifndef VECTOR_ICON_H
#define VECTOR_ICON_H
struct vector_icon {
uint8* data;
size_t size;
};
#endif // VECTOR_ICON_H

View File

@ -4,9 +4,11 @@
*/
#include "FileTypes.h"
#include "IconView.h"
#include "MimeTypeListView.h"
#include <new>
#include <stdlib.h>
#include <string.h>
#include <Application.h>
#include <AppFileInfo.h>
@ -24,9 +26,8 @@
#include <Roster.h>
#include <Size.h>
#include <new>
#include <stdlib.h>
#include <string.h>
#include "FileTypes.h"
#include "MimeTypeListView.h"
#undef B_TRANSLATION_CONTEXT
@ -182,6 +183,7 @@ Icon::SetTo(const BAppFileInfo& info, const char* type)
uint8* data;
size_t size;
if (info.GetIconForType(type, &data, &size) == B_OK) {
// we have the vector icon, no need to get the rest
AdoptData(data, size);
@ -253,6 +255,7 @@ Icon::CopyTo(BAppFileInfo& info, const char* type, bool force) const
status = info.SetIconForType(type, fMini, B_MINI_ICON);
if (fData != NULL || force)
status = info.SetIconForType(type, fData, fSize);
return status;
}
@ -285,6 +288,7 @@ Icon::CopyTo(BMimeType& type, bool force) const
status = type.SetIcon(fMini, B_MINI_ICON);
if (fData != NULL || force)
status = type.SetIcon(fData, fSize);
return status;
}
@ -1264,6 +1268,7 @@ IconView::_SetIcon(BBitmap* large, BBitmap* mini, const uint8* data,
fType.SetIcon(mini, B_MINI_ICON);
if (data != NULL || force)
fType.SetIcon(data, size);
// the icon shown will be updated automatically - we're watching
// any changes to the MIME database
} else if (fIconData != NULL) {