2 * Copyright 2008 Ralf Schülke, ralf.schuelke@googlemail.com.
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT License.
8 * Ralf Schülke, ralf.schuelke@googlemail.com
9 * John Scipione, jscipione@gmail.com
25 #include "PairsWindow.h"
28 #undef B_TRANSLATION_CONTEXT
29 #define B_TRANSLATION_CONTEXT "Pairs"
32 const char* kSignature
= "application/x-vnd.Haiku-Pairs";
34 static const size_t kMinIconCount
= 64;
35 static const size_t kMaxIconCount
= 384;
38 // #pragma mark - Pairs
43 BApplication(kSignature
),
58 fWindow
= new PairsWindow();
64 Pairs::RefsReceived(BMessage
* message
)
66 fWindow
->PostMessage(message
);
71 Pairs::MessageReceived(BMessage
* message
)
73 BApplication::MessageReceived(message
);
78 Pairs::QuitRequested()
80 // delete vector icons
81 for (IconMap::iterator iter
= fIconMap
.begin(); iter
!= fIconMap
.end();
83 delete fIconMap
[iter
->first
];
90 // #pragma mark - Pairs private methods
94 Pairs::_GetVectorIcons()
96 // Load vector icons from the MIME type database and add a pointer to them
97 // into a std::map keyed by a generated hash.
100 if (BMimeType::GetInstalledTypes("application", &types
) != B_OK
)
104 for (int32 i
= 0; types
.FindString("types", i
, &type
) == B_OK
; i
++) {
105 BMimeType
mimeType(type
);
106 if (mimeType
.InitCheck() != B_OK
)
112 if (mimeType
.GetIcon(&data
, &size
) != B_OK
) {
113 // didn't find an icon
117 size_t hash
= 0xdeadbeef;
118 for (size_t i
= 0; i
< size
; i
++)
119 hash
= 31 * hash
+ data
[i
];
121 if (fIconMap
.find(hash
) != fIconMap
.end()) {
122 // key has already been added to the map
127 vector_icon
* icon
= (vector_icon
*)malloc(sizeof(vector_icon
));
137 // found a vector icon, add it to the list
138 fIconMap
[hash
] = icon
;
139 if (fIconMap
.size() >= kMaxIconCount
) {
140 // this is enough to choose from, stop eating memory...
145 if (fIconMap
.size() < kMinIconCount
) {
147 snprintf(buffer
, sizeof(buffer
),
148 B_TRANSLATE_COMMENT("Pairs did not find enough vector icons "
149 "to start; it needs at least %zu, found %zu.\n",
150 "Don't translate \"%zu\", but make sure to keep them."),
151 kMinIconCount
, fIconMap
.size());
152 BString
messageString(buffer
);
153 BAlert
* alert
= new BAlert("Fatal", messageString
.String(),
154 B_TRANSLATE("OK"), NULL
, NULL
, B_WIDTH_FROM_WIDEST
,
156 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
163 // #pragma mark - main