HaikuDepot: notify work status from main window
[haiku.git] / src / apps / haikudepot / model / LocalIconStore.cpp
blob5cc882312743dbe82a815494df2efbc693a1587d
1 /*
2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "LocalIconStore.h"
8 #include <stdio.h>
10 #include <Directory.h>
11 #include <FindDirectory.h>
13 #include "Logger.h"
14 #include "ServerIconExportUpdateProcess.h"
15 #include "StorageUtils.h"
18 LocalIconStore::LocalIconStore(const BPath& path)
20 fIconStoragePath = path;
24 LocalIconStore::~LocalIconStore()
29 bool
30 LocalIconStore::_HasIconStoragePath() const
32 return fIconStoragePath.InitCheck() == B_OK;
36 /* This method will try to find an icon for the package name supplied. If an
37 * icon was able to be found then the method will return B_OK and will update
38 * the supplied path object with the path to the icon file.
41 status_t
42 LocalIconStore::TryFindIconPath(const BString& pkgName, BPath& path) const
44 BPath bestIconPath;
45 BPath iconPkgPath(fIconStoragePath);
46 bool exists;
47 bool isDir;
49 if ( (iconPkgPath.Append("hicn") == B_OK)
50 && (iconPkgPath.Append(pkgName) == B_OK)
51 && (StorageUtils::ExistsObject(iconPkgPath, &exists, &isDir, NULL)
52 == B_OK)
53 && exists
54 && isDir
55 && (_IdentifyBestIconFileAtDirectory(iconPkgPath, bestIconPath)
56 == B_OK)
57 ) {
58 path = bestIconPath;
59 return B_OK;
62 path.Unset();
63 return B_FILE_NOT_FOUND;
67 status_t
68 LocalIconStore::_IdentifyBestIconFileAtDirectory(const BPath& directory,
69 BPath& bestIconPath) const
71 StringList iconLeafnames;
73 iconLeafnames.Add("icon.hvif");
74 iconLeafnames.Add("64.png");
75 iconLeafnames.Add("32.png");
76 iconLeafnames.Add("16.png");
78 bestIconPath.Unset();
80 for (int32 i = 0; i < iconLeafnames.CountItems(); i++) {
81 BString iconLeafname = iconLeafnames.ItemAt(i);
82 BPath workingPath(directory);
83 bool exists;
84 bool isDir;
86 if ( (workingPath.Append(iconLeafname) == B_OK
87 && StorageUtils::ExistsObject(
88 workingPath, &exists, &isDir, NULL) == B_OK)
89 && exists
90 && !isDir) {
91 bestIconPath.SetTo(workingPath.Path());
92 return B_OK;
96 return B_FILE_NOT_FOUND;