2 * Copyright 2002-2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
7 * Axel Dörfler, axeld@pinc-software.de
8 * Ingo Weinhold, ingo_weinhold@gmx.de
12 #include <mime/AppMetaMimeCreator.h>
16 #include <AppFileInfo.h>
24 #include <AutoLocker.h>
25 #include <mime/Database.h>
26 #include <mime/database_support.h>
27 #include <mime/DatabaseLocation.h>
35 AppMetaMimeCreator::AppMetaMimeCreator(Database
* database
,
36 DatabaseLocker
* databaseLocker
, int32 force
)
38 MimeEntryProcessor(database
, databaseLocker
, force
)
43 AppMetaMimeCreator::~AppMetaMimeCreator()
49 AppMetaMimeCreator::Do(const entry_ref
& entry
, bool* _entryIsDir
)
52 status_t status
= file
.SetTo(&entry
, B_READ_ONLY
| O_NOTRAVERSE
);
56 bool isDir
= file
.IsDirectory();
57 if (_entryIsDir
!= NULL
)
60 if (isDir
|| !file
.IsFile())
63 BAppFileInfo
appInfo(&file
);
64 status
= appInfo
.InitCheck();
68 // Read the app sig (which consequently keeps us from updating
69 // non-applications, since we get an error if the file has no
72 status
= file
.ReadAttrString("BEOS:APP_SIG", &signature
);
76 if (!BMimeType::IsValid(signature
))
79 InstallNotificationDeferrer
_(fDatabase
, signature
.String());
81 if (!fDatabase
->Location()->IsInstalled(signature
)) {
82 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
83 fDatabase
->Install(signature
);
87 status
= fDatabase
->Location()->OpenType(signature
, typeNode
);
94 && (fForce
|| typeNode
.GetAttrInfo(kPreferredAppAttr
, &info
) != B_OK
)) {
95 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
96 status
= fDatabase
->SetPreferredApp(signature
, signature
);
99 // Short Description (name of the application)
102 || typeNode
.GetAttrInfo(kShortDescriptionAttr
, &info
) != B_OK
)) {
103 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
104 status
= fDatabase
->SetShortDescription(signature
, entry
.name
);
109 && (fForce
|| typeNode
.GetAttrInfo(kAppHintAttr
, &info
) != B_OK
)) {
110 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
111 status
= fDatabase
->SetAppHint(signature
, &entry
);
116 && (fForce
|| typeNode
.GetAttrInfo(kIconAttr
, &info
) != B_OK
)) {
119 if (appInfo
.GetIcon(&data
, &size
) == B_OK
) {
120 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
121 status
= fDatabase
->SetIcon(signature
, data
, size
);
126 BBitmap
miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK
, B_CMAP8
);
128 && (fForce
|| typeNode
.GetAttrInfo(kMiniIconAttr
, &info
) != B_OK
)) {
129 if (appInfo
.GetIcon(&miniIcon
, B_MINI_ICON
) == B_OK
) {
130 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
131 status
= fDatabase
->SetIcon(signature
, &miniIcon
, B_MINI_ICON
);
135 BBitmap
largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK
, B_CMAP8
);
137 && (fForce
|| typeNode
.GetAttrInfo(kLargeIconAttr
, &info
) != B_OK
)) {
138 if (appInfo
.GetIcon(&largeIcon
, B_LARGE_ICON
) == B_OK
) {
139 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
140 status
= fDatabase
->SetIcon(signature
, &largeIcon
, B_LARGE_ICON
);
145 bool setSupportedTypes
= false;
146 BMessage supportedTypes
;
149 || typeNode
.GetAttrInfo(kSupportedTypesAttr
, &info
) != B_OK
)) {
150 if (appInfo
.GetSupportedTypes(&supportedTypes
) == B_OK
)
151 setSupportedTypes
= true;
154 // defer notifications for supported types
156 for (int32 i
= 0; supportedTypes
.FindString("types", i
, &type
) == B_OK
; i
++)
157 fDatabase
->DeferInstallNotification(type
);
159 // set supported types
160 if (setSupportedTypes
) {
161 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
162 status
= fDatabase
->SetSupportedTypes(signature
, &supportedTypes
, true);
165 // Icons for supported types
166 for (int32 i
= 0; supportedTypes
.FindString("types", i
, &type
) == B_OK
;
172 && appInfo
.GetIconForType(type
, &data
, &size
) == B_OK
) {
173 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
174 status
= fDatabase
->SetIconForType(signature
, type
, data
, size
);
179 && appInfo
.GetIconForType(type
, &miniIcon
, B_MINI_ICON
) == B_OK
) {
180 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
181 status
= fDatabase
->SetIconForType(signature
, type
, &miniIcon
,
186 && appInfo
.GetIconForType(type
, &largeIcon
, B_LARGE_ICON
) == B_OK
) {
187 AutoLocker
<DatabaseLocker
> databaseLocker(fDatabaseLocker
);
188 status
= fDatabase
->SetIconForType(signature
, type
, &largeIcon
,
193 // undefer notifications for supported types
194 for (int32 i
= 0; supportedTypes
.FindString("types", i
, &type
) == B_OK
; i
++)
195 fDatabase
->UndeferInstallNotification(type
);
202 } // namespace Storage
203 } // namespace BPrivate